0

I am working with this third party service provider where i have to fetch / filter some data from them. The search filter parameters are complex in nature and contains too many filter params. I have tried to use querystring values and with querystring, i find it more difficult to send data since the data i have to send may contain an array of objects.

With JSON request body even with HTTP GET request, I find it extremely easy to process the request and did the testing using Insomnia REST client with ease. However POSTman REST client doesn't allow to send body parameters with GET request.

I have seen others using POST request to fetch / filter data from the api for the same purpose. POST HTTP request can be used to fetch data, but is it good from the technical standpoint? Is it recommended practice to send JSON request body values with GET request?

shrawan_lakhe
  • 358
  • 2
  • 5
  • 22
  • 1
    Please note that the GET request size is much smaller than POST request size. If you have a lot of data in request body, you should use POST. Also, the parameter in GET request should be in query string, instead of body parameters. – Raptor Feb 15 '18 at 03:20
  • Is it alright if i used POST request to fetch the data? won't it affect the REST principles – shrawan_lakhe Feb 15 '18 at 05:52
  • 1
    GET or POST will return data (a.k.a. able to fetch data), but in REST principle, GET is the right way to fetch data. – Raptor Feb 15 '18 at 06:01

1 Answers1

2

Not sure how much control you might have on the protocol or you have any middleware, but an HTTP GET usually doesn't have a body, I've even seen smart firewalls and hosting services strip any body by default. If you want to stay "close" to clean REST, you might consider adding a "/query" to your resource path and do a POST to that endpoint; it's a bit "RPC-ish" but not too bad. Another option would be to have a completely independent query service that could be using another protocol such as JSON-RPC.

Simon Berthiaume
  • 643
  • 4
  • 11
  • For me using POST to fetch data is not such a good idea. To follow the REST principles, we need to use GET to fetch data. Can you recommend which would be better? – shrawan_lakhe Feb 15 '18 at 05:51
  • According to recommendations you should use GET but if you need request body you should consider POST. Another problem which you may face with GET request - URL is limited to 2000 characters (https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers). – Justinas Jakavonis Feb 15 '18 at 08:07