Example:
URL: http://example.com/collection/a%20search%20term
Method: GET
Response: All items in collection
matching a search term
.
Problem: The search term may be so long that it breaks the web server's maximum URL length.
How do I allow extremely long search terms and still stay RESTful?
The REST API supports Uniform Resource Locators (URLs) with a length of up to 6000 characters. To avoid exceeding this limit, it is important to be aware of URL encoding.
A Diffbot Extract API request will timeout after a maximum of 180 seconds (3 mins). If a request reaches 180 seconds, it will be automatically timed-out and an error returned.
Query parameters are passed after the URL string by appending a question mark followed by the parameter name , then equal to (“=”) sign and then the parameter value. Multiple parameters are separated by “&” symbol.
So, yes, you can send a body with GET, and no, it is never useful to do so. This is part of the layered design of HTTP/1.1 that will become clear again once the spec is partitioned (work in progress). Yes, you can send a request body with GET but it should not have any meaning.
For inspiration, I just looked at Google Translate's API v2, which is "using the RESTful calling style."
Naturally, texts to be translated can be quite long. And so Google optionally allows sending a request with POST
, but with a twist:
To use
POST
, you must use theX-HTTP-Method-Override
header to tell the Translate API to treat the request as aGET
(useX-HTTP-Method-Override: GET
).
So it is possible to semantically transform a POST
request into a GET
request.
(This discovery led me to add the x-http-method-override tag to my question.)
REST does not restrict POST to creation. Be careful with mapping CRUD to HTTP methods and assume that's RESTful. POST is the method used for any action that isn't standardized by HTTP.
Since the standard doesn't establish a limit for URIs, this can be considered a broken implementation, and it's ok to fix it. As long as the workaround is loosely coupled to your API, you are still RESTful. This means your API shouldn't implement a translation or override directly, but on a pre-processor of some kind that rewrites the request properly. It should be clearly documented somewhere that this is due to a broken implementation, and you expect it to eventually become obsolete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With