Should you send a payload in an HTTP GET request?

Should you send a payload in an HTTP GET request?

It is a common myth that we could not pass the request body in the HTTP GET request. HTTP 1.1 specification neither enforces nor suggests this behavior.

This means it is up to implementing the application web servers- Flask, uWSGI, etc.- to see if it parses the request body in the HTTP GET request. To do this, just check the request object you would be getting in your favorite framework.

What can we do with this information?

Say you are modeling an analytics service like Google Analytics in which you are exposing an endpoint that returns you the data point depending on the requirements. The requirements specified here could be a large, complex JSON.

Passing this query in the URL of the GET request as a query param is not convenient as it would require you to serialize and escape the JSON string before passing.

This is a perfect use case where the complex JSON query can be passed as a request body in the HTTP GET request, giving a good user experience.

So, does any popular tool uses this convention?

Yes. ElasticSearch- one of the most popular search utilities, uses this convention.

The search endpoint of ElasticSearch is a GET endpoint where the complex search queries in JSON format are sent in the request payload.

Here's the video of my explaining this in-depth 👇 do check it out

Can we send data in an HTTP GET request? Most people think, No. The truth is, we can send the data in the request payload of an HTTP GET request so long as our webserver can understand it.

In this video, we go through the HTTP 1.1 specification and see what it says about the GET requests, write a simple Flask application to see that we can indeed process the payload of a GET request if we want to, and, more importantly, go through a real-world example where it was essential to send data in the request payload.

Outline:

  • 00:00 HTTP GET Request
  • 01:53 What does HTTP 1.1 specification say?
  • 05:38 Request payload in Python Flask
  • 07:18 ElasticSearch using request payload for search
  • 10:40 When to use HTTP request payload in a GET request

You can also

Thank you so much for reading 🖖 If you found this helpful, do spread the word about it on social media; it would mean the world to me.

You can also follow me on your favourite social media LinkedIn, and Twitter.

Yours truly,

Arpit

arpitbhayani.me

Until next time, stay awesome :)

No alt text provided for this image


I teach a course on System Design where you'll learn how to intuitively design scalable systems. The course will help you

  • become a better engineer
  • ace your technical discussions
  • get you acquainted with a massive spectrum of topics ranging from Storage Engines, High-throughput systems, to super-clever algorithms behind them.

I have compressed my ~10 years of work experience into this course, and aim to accelerate your engineering growth 100x. To date, the course is trusted by 600+ engineers from 10 different countries and here you can find what they say about the course.

Together, we will build some of the most amazing systems and dissect them to understand the intricate details. You can find the week-by-week curriculum and topics, benefits, testimonials, and other information here https://arpitbhayani.me/masterclass.

Just a question with fellow developers, How can I cache post call on CDN. Passing big payload with Post call and can't convert it into get

Like
Reply

Just because you can , it doesn't mean you should . By the way, if we are talking about possibilities, the HTTP protocol actually enables us to even develop custom methods, not being limited to GET, POST, PUT, etc. . I could develop a method called SAUDATE if I wanted to . But is that a good idea ?

Like
Reply

One example of HTTP GET with payload is in Elastic Search APIs where query requests are GETs but the query is sent in the request payload. While you can send the payload in GET requests, and it will be sent over the wire as well, many server implementations or application processing frameworks will ignore the same, and parsed framework request object may not show up in the payload.

Like
Reply

You can, but it's bad practice. If you want to use a body, do a POST.

Like
Reply

Very interesting article

Like
Reply

To view or add a comment, sign in

More articles by Arpit Bhayani

  • How Much Are People Willing to Bet on You?

    This edition of the newsletter contains a write-up to help you grow in your career a video I posted a paper I read Btw,…

    6 Comments
  • How to Get Leadership to Say Yes to Your Project

    This edition of the newsletter contains a write-up to help you grow in your career a video I posted a paper I read Btw,…

    2 Comments
  • Don’t Let Your Best Ideas Die in Silence

    This edition of the newsletter contains a write-up to help you grow in your career a video I posted a paper I read Btw,…

    5 Comments
  • Be the Person Everyone Wants to Work With

    This edition of the newsletter contains a write-up to help you grow in your career a video I posted a paper I read By…

    5 Comments
  • The XY Problem and How to Avoid It

    This edition of the newsletter contains a write-up to help you grow in your career a video I posted a paper I read By…

    4 Comments
  • The Startup Hiring Lie Nobody Talks About

    This edition of the newsletter contains a write-up to help you grow in your career a video I posted a paper I read Btw,…

    7 Comments
  • You Won't Be Promoted Unless You Ask

    This edition of the newsletter contains a write-up to help you grow in your career a video I posted a paper I read Btw,…

    3 Comments
  • It's Not Enough to be Right; Learn to be Heard

    This edition of the newsletter contains a write-up to help you grow in your career a video I posted a paper I read Btw,…

    7 Comments
  • Career Longevity Beats Constant Job Hopping

    This edition of the newsletter contains a write-up to help you grow in your career a video I posted a paper I read Btw,…

    5 Comments
  • No One Ships Great Software Alone

    This edition of the newsletter contains a write-up to help you grow in your career a video I posted a paper I read I…

    6 Comments

Others also viewed

Explore content categories