Answer the question
In order to leave comments, you need to log in
Why is the id sent to the rest API in the url itself, and not in the date or in the queue?
Why is the id sent to the rest API in the url itself, and not in the date or in the queue? It is not convenient to work with this either on the back or on the front, when you need to parse and send some data (id) in a certain way, and others differently.
Answer the question
In order to leave comments, you need to log in
If the request is made using the GET method, then the parameters are obtained from the url. In other methods ( POST, PUT, DELETE ) data is received from the request body and url.
Using the GET method, for example, all site news are received without passing any parameters.
If you need to get one piece of news, for example, pass its id.
The GET method sends all requests from the browser (what is written in the address bar).
query parameters are needed, for example, to organize a limit for displaying news on one page.
Not convenient - do not send. These are all recommendations, not rules. But in general, there is nothing inconvenient here - the frameworks have long parsed REST easily and not forcibly.
In general - /user/123 and /user?id=123 are quite equivalent addressing
The question is about adopting REST rules. At first I also thought so - what for all sorts of GET, PATCH, PUT are needed. Why, if there is a POST and everything is fine in it, you can pass it in the request body and parse it too. However, now I’m making an application completely from scratch and backing up to Yii according to all the rules - GET - getting data, POST - creating, etc.
If you deal with a specific framework, creating such an API becomes much easier when the number of functions of this API exceeds a couple dozen. And for unpretentious heels or two, you can break the rules.
But when it comes time to figure out why something went wrong and / or something needs to be added / redone - such a "simple" API turns into a nightmare. And it's harder to document
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question