tags:

views:

2237

answers:

6

I'm developing a new REST-full webservice for our application.

When doing a GET on certain entities, clients can request the contents of the entity. If they want to add some parameters (for example sorting a list) they can add these parameters in the query string.

Alternatively I want people to be able to specify these parameters in the request body. HTTP/1.1 does not seem to explicitly forbid this. This will allow them to specify more information, might make it easier to specify complex xml requests.

My questions:

  • Is this a good idea altogether?
  • Will HTTP clients have issues with using request bodies within a GET request?

http://tools.ietf.org/html/rfc2616

+11  A: 

While you can do that, insofar as it isn't explicitly precluded by the HTTP specification, I would suggest avoiding it simply because people don't expect things to work that way. There are many phases in an HTTP request chain and while they "mostly" conform to the HTTP spec, the only thing you're assured is that they will behave as traditionally used by web browsers. (I'm thinking of things like transparent proxies, accelerators, A/V toolkits, etc.)

This is the spirit behind the Robustness Principle roughly "be liberal in what you accept, and conservative in what you send", you don't want to push the boundaries of a specification without good reason.

However, if you have a good reason, go for it.

caskey
A: 

I wouldn't advise this, it goes against standard practices, and doesn't offer that much in return. You want to keep the body for content, not options.

cloudhead
+6  A: 

You will likely encounter problems if you ever try to take advantage of caching. Proxies are not going to look in the GET body to see if the parameters have an impact on the response.

Darrel Miller
Good answer; I'll find a way around it
Evert
Using ETag/Last-Modified header fields help in this way: when a "conditional GET" is used, the proxies/caches can act on this information.
jldupont
A: 

Perhaps I am missing the point, but why don't you use a POST instead if you want to send the data in the body and not the URL?

Flavius Stef
POST, GET, DELETE and PUT all have very different meanings.. POST is already used on some urls for a different purpose.
Evert
POST is not the right verb for a RESTful request to read a resource.
Andrew Vit
+1  A: 

What you're trying to achieve has been done for a long time with a much more common method, and one that doesn't rely on using a payload with GET.

You can simply build your specific search mediatype, or if you want to be more RESTful, use somehting like OpenSearch, and POST the request to the URI the server instructed, say /search. The server can then generate the search result or build the final URI and redirect using a 303.

This has the advantage of following the traditional PRG method, helps cache intermediaries cache the results, etc.

That said, URIs are encoded anyway for anything that is not ascii, and so are application/x-www-form-urlencoded and multipart/form-data. I'd recommend using this rather than create yet another custom json format if your intention is to support ReSTful scenarios.

serialseb
+5  A: 

Roy Fielding's comment about including a body with a GET request. Yes, you can send a request body with GET but the server will ignore it.

Paul Morgan