Faraz
Faraz

Reputation: 113

GET request with body VS POST for retrieving a large resource

According to many posts like this one, having a GET request with a body is not very common.

On the other hand, one of the best practices in REST is to use POST only when we want to make a change on the resources and GET when we just want to retrieve a resource.

So my question is what is the preferred way of getting a resource with a very large payload? should I prioritize HTTP best practices and use POST with a body even though I'm not actually changing anything or stick to the RESTFUL practices and use a GET with a body?

Upvotes: 11

Views: 18339

Answers (1)

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57257

"HTTP best practices" and "RESTFUL practices" are the same in this context: using the GET method token with a request body is bad practice.


use POST only when we want to make a change on the resources

That's not quite right - see it is okay to use POST (Fielding, 2009). Roughly summarized, POST is the HTTP method with the fewest constraints. We can always use it, but we should prefer to use a more specific method when the semantics of the request fits within the constraints of the method.

For fetching a representation of a resource, we prefer to use GET, because that best communicates the semantics of the request to general purpose HTTP components, so that they can correctly interpret the semantics of the request and do useful things.

But that depends on being able to completely identify the resource using the information in the request line. If your identifier is too long, then that won't work, and you'll need to fall back to using POST, copying the "identifier" into the body of the request.

That "works", but the trade off is that general purpose components aren't going to know that the GET constraints still apply, and therefore aren't going to be able to anything intelligent (automatically retrying if a response is lost, caching results, and so on).


In late 2020, the HTTP-WG adopted a proposal to create a standard for a new method token, that would act as a "GET with a body". So at some point, we should start to see a registered standard, and conforming implementations, and so on.

Upvotes: 11

Related Questions