Should you send payload in an HTTP GET request?

Sharing is Caring

HTTP defines a set of different request methods. There are request methods like GET, POST, PUT, DELETE, and others.

I often get asked if it makes sense to have GET requests have a body. There are some advantages to having the GET request have a body – it doesn’t have a length restriction, it’s quite a bit easier to encode, it can accept JSON or XML. There’s also quite a few disadvantages too.

The GET method should only be used to retrieve data, it should be safe, idempotent, and cacheable. If the GET method changes the response based on what is in the body, it’s not cacheable. If the body changes data it’s not safe or potentially idempotent.

While the GET request supports sending a body, I prefer not to do it. I think that breaking caching and proxies isn’t worth the squeeze in most situations.

There are some popular APIs and products that implement it like Elasticsearch. I prefer to create a POST method that allows for searching.

You can read more about the HTTP methods and how I build URIs in Difference between HTTP Methods (Get & Post) and Understanding how to use REST API and HTTP.

Sharing is Caring