Answer the question
In order to leave comments, you need to log in
How should the database interact with client applications?
Hello!
I am developing a file storage.
Everything seems to be working, but it became interesting to me how the database (Mysql) should interact with client applications?
At the moment, there is only a web client that works with the database by directly sending requests.
But in the future, I would like to scale the project, create a client for android.
Tell me, please, your options for working with the database.
Answer the question
In order to leave comments, you need to log in
Not exactly the right question.
The database itself should not interact with clients (with rare exceptions, I believe), in any case, this is the task of the layer.
And then the options: you can make separate layers for the API and for the web, in simple cases you can get by with one (something like if (wants json) { return json; } else { return html} )
We need a controller that acts as a layer from the web client to the base to make it universal and configurable. For example, a controller receives a request from outside (it doesn’t matter from whom exactly):
[{action: getArticle, target: android, count: 20, hash: 5674%4%$7^5bbss, and so on...}]
And when our the controller is able to parse and analyze the jason that came in the request, it is already clear to him what to do next. For example, I did this in my service, if the request indicates that ajax: true, then I give only data in the form of json, if it is indicated that ajax: false, then I give the generated html code. The main thing is to think over a universal controller, not forgetting about safety.
And who needs to distribute an API like, if you want to get 20 records, send such and such a request ...
Of course, there are different types of requests for different needs and with different security, I gave only the general meaning of the work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question