1

We found ourselves in a dead end when trying to follow standards as we need to build a request that should be a GET and should have a meaning Body.

The request just wants to retrieve some data, no modification inside the database, just getting some data. But at the same time we need to send an array of ids for the objects we want to retrieve, and no, these objects can't be indexed in any way so we really need to send the list of ids or alternatively make 100 requests to the server to get them one by one. That's not gonna happen.

We could also add the list to the URL, but we can't be sure the URL won't end up being too long if the list of ids were to be too big. So to ensure the system doesn't fail we want to use the Body.

I read that a GET can have a Body, but only if it isn't meaningful: HTTP GET with request body

Yes. In other words, any HTTP request message is allowed to contain a message body, and thus must parse messages with that in mind. Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request. The requirements on parsing are separate from the requirements on method semantics.

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).

....Roy

But our Body IS meaningful, which takes us to have to decide between unfollowing HTTP standards or unfollowing REST standards.

Is there any alternative to that? (It's not that this blocks us but I would like to know the answer).

Thank you very much.

Community
  • 1
  • 1
Ruben.Canton
  • 1,103
  • 3
  • 14
  • 29
  • [Your most practical solution is probably \[..\] an HTTP POST. This isn't RESTful; you should be using GETs for read-only queries. And you'll lose some advantages of the REST approach with caching of GETs and the like. On the other hand it will work correctly, and simply, with a large variety of Internet infrastructure and software libraries](http://stackoverflow.com/questions/1266596/what-is-the-best-way-to-design-a-http-request-when-somewhat-complex-parameters-a) – CodeCaster Jan 16 '15 at 11:04
  • possible duplicate of [HTTP GET with request body](http://stackoverflow.com/questions/978061/http-get-with-request-body) – Ginden Jan 16 '15 at 11:27
  • Many REST clients doesn't allow body in GET. [This discussion (HTTP GET with request body)](http://stackoverflow.com/questions/978061/http-get-with-request-body) explains why you should violate REST principles. – Ginden Jan 16 '15 at 11:30
  • Thanks both. Yes, we already thought it was wiser to unfollow REST than to unfollow HTTP as some tools may have trouble with posting a Body in a GET while none will complain that our POST isn't modifying anything. ;) – Ruben.Canton Jan 16 '15 at 11:34

0 Answers0