Akka Jaworek Akka Jaworek - 2 months ago 9
HTTP Question

GET method with list of paramethers as body or POST method?

I need to create an endpoint which will provide list of objects, i need to pass as request body list of ID's of objects i want to retrieve. As far i know this should be done by GET method since its only retrieving object and not modifying them, but when i want to call it from client side using

RestTemplate
, it does not have any method for
GET
to pass body. However this is archiveable with
POST
method. Should i use
POST
instead of
GET
or is there other solution?

EDIT:for everyone with simmilar problem, this theard helps a lot:

HTTP GET with request body

Answer

If you want to stick to GET which is semantically more correct you need to pass the list of IDs as a Request parameter instead of body because GET doesn't define a body.

Using POST in which case you can pass the list in the body, is generally fine also though some sticklers will state that it isn't semantically correct.

Note that POST is sometimes preferred depending how complex or long the query data is.

Comments