Search code examples
web-servicesrestrestful-architecture

REST: GET calls


I am reading a book on REST. It recommends for GET requests, the method name should be in HTTP method header and any parameters required to retrieve the data should be in the URI. Example: www.flickr.com/search=penguins

Now, in many cases, a number of parameters are required to retrieve the data. For example, name of application, name of the user, address of the user etc. If a number of parameters are required to retrieve the data, is it good practice include this info the URI or can we pass a JSON object and use HTTP POST?

Or would that make the service not RESTful


Solution

  • As with all things, there are tradeoffs. If you filter using GET with query parameters and your data is cacheable, then caches will be able to store the results of those requests and save work later. You are limited, though, on the size of your query string. The upper bound from a browser is allowed to be 2k characters, but most browsers support at least 8k.

    If you filter using POST and a filter body, you can save that filter as a resource and refer to it later, including in later GET calls. You also have no upper bound on the size of the query.