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

Brian is a software architect and technology leader living in Niagara Falls with 13+ years of development experience. He is passionate about automation, business process re-engineering, and building a better tomorrow.

Brian is a proud father of four: two boys, and two girls and has been happily married to Crystal for more than ten years. From time to time, Brian may post about his faith, his family, and definitely about technology.