Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST API: GET request with body

I want to implement a REST API and need a body on my GET requests. (Like discussed here: HTTP GET with request body)

Are there http clients which are not able to send a body with a GET request? Fiddler is able to do it, although the message box is red.

like image 860
user437899 Avatar asked Jun 18 '12 21:06

user437899


People also ask

Can a rest get request have a body?

GET requests don't have a request body, so all parameters must appear in the URL or in a header. While the HTTP standard doesn't define a limit for how long URLs or headers can be, mostHTTP clients and servers have a practical limit somewhere between 2 kB and 8 kB.

How do you pass a request body on REST API?

The first REST API request in a session must be a sign-in request. This is a POST request that sends the user credentials in the body of the request. Because this is a POST request, the request must include the Content-Type header. You can send your the body of the request block as XML or JSON.


1 Answers

As a general rule, the idea of a GET in REST is that any of your parameters are sent in the URL. As the answer on the question you included indicates, it's doable but misses the point of REST, which is to have a consistent webbish interface. If you want to pass complex data to your endpoint, you probably want to use a POST, which your users will expect to have a body for. I'd highly recommend reconsidering that implementation.

But to your actual question, sure there are clients that can't send a body on a GET. Mostly I'd imagine your clients will be programmatic, say, python's urlib2, and while you can set a body on GET, it is not really the intended use of the module, so you're forcing the programmer to get weird. More importantly, the idea of the REST api is to be client-agnostic, which is why it sounds to me like your API design should be reworked here.

like image 69
Ben Avatar answered Sep 26 '22 20:09

Ben