2

I am designing a RESTful API. I need to retrieve a resource (complex report) passing a really long list of filters. Something like this:

http://example.com/orders?query=a-very-long-list-of-filters

So I should use GET HTTP verb but if URI exceeds the allowed URL length (by browser, web server or intermediate proxies), can I use POST request with JSON body encapsulating filters to do so? The POST verb is intended for creating resources and updating partially but not for retrieving resources. How can I solve this situation. Please tell me a solution that conforms to REST fundamentals because encoding URL to decrease the length is not an agreeable solution. I have been researching a lot about this but I didn't find a proper and definitive guidelines. Any help will be appreciated.

govin
  • 6,445
  • 5
  • 43
  • 56
Delmo
  • 2,188
  • 2
  • 20
  • 29
  • How long are you expecting your query string to be? Have a look at this article. Practically, I doubt you'll reach a limit - especially for an API http://stackoverflow.com/a/812962/2812842 – scrowler Mar 03 '14 at 05:04
  • Thanks @scrowler for the link. I have already checked some of this sort of comments but I am not sure how long the url can be so I have no guarantee it doesn't exceed 2048 caracters (case of IE). It depends to the UI chosen filters and indeed it could be so so long. – Delmo Mar 03 '14 at 12:38

1 Answers1

1

You can use a POST request as an alternative to GET request to send any large data that might exceed the maximum allowed query string length, but to conform to REST standards, it is recommended that you also send a 'X-HTTP-Method-Override: GET' header while doing so to tell the server to treat it as a GET request. I have seen some some well known libraries such as Google Translate allow this - https://cloud.google.com/translate/v2/using_rest?csw=1#Translate

govin
  • 6,445
  • 5
  • 43
  • 56