Wednesday, February 20, 2019

REST and Payload

I have seen many ways REST webservices has been implemented and some are up to the standard and some looks more specific with their implementation.
Once we got a REST service code where all the calls were implemented using only POST.
In REST there are no hard rules, nevertheless it is nice if we can follow the conventions. Looking at various implementations, i was little confused with the what was the real way to do so sometimes.
So i did a few research on the internet and read what people had written.

Basic confusion with GET and DELETE where whether we can include a payload or body with the request call.
As there are no hard rules, REST does not force to not to do so, and still you can include a body for GET and DELETE.
Specially we do to make code looks more better or for better implementation. eg: create Search criteria, Filer criteria , most send inside body. This looks more object oriented. In my experience we did a search implementation for Apache SOLR. There i send all the search related info as params (search parms ) with the URL.

Conclusion:
REST --> GET and DELETE avoid using a payload or body (avoid @RequestBody use @PathVariable or URI with URI builder )



https://stackoverflow.com/questions/978061/http-get-with-request-body
https://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request

No comments:

Post a Comment