N
N
NameOf Var2020-03-24 11:51:12
RESTful API
NameOf Var, 2020-03-24 11:51:12

When should we use Query and when should we use Body in HTTP?

Hello. Can you please tell me if there are any restrictions in the HTTP/REST spec that put a limit on using Query or Body?

For example, the browser does not allow sending a GET request with Body parameters, but what about the other methods? Can I, for example, use POST / PUT / PATCH / DELETE with a Query request (if there are no secret data, like passwords)? And what is the best choice during the development of the API architecture? Is there any documentation that clearly says that you need to use Body with such and such methods, Query - with such and such?

UPD. I remembered three more questions:
1) can we use verbs in routings? Like /users/password/reset?
2) This question is related to the difference between PUT and PATCH. For example, I want to update a user's password.
Is there a difference between these two routings: PATCH /user or better PUT /user/password ?
3) Should we always use the plural in naming collections?
For example, there is a GET /user-management/users method that will return a list of ALL users. And there is a DELETE /user-management/user?id=123 method, which will delete only ONE user. The question is: do I need to change the delete API to /user-management/user S or can I leave it as it is?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IDONTSUDO, 2020-03-24
@IDONTSUDO

The very concept of REST is so vague that there is no standard answer to your question. What you use and see is most often not REST in the academic sense in which it was created.
Here's a good opinion on the matter. But I couldn't find confirmation of it anywhere.
https://habr.com/ru/company/yandex/blog/265569/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question