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.

Alexandre Saudate

Senior Software Engineer @ Ratepay

10 个月

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 ?

回复
Arpit Agrawal

Senior Software Engineer at Atlassian | Technical and Career Mentor

1 年

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.

回复
Ken Yee

Sr Eng at Netflix

2 年

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

回复

Very interesting article

回复
Rishabh Singh Mewar

SDE 2 (Distributed Systems) || NMIMS | BITS Pilani || IBM Labs | EY LLP | Standard Chartered | GSPANN | Coforge

2 年

Thank you Arpit Bhayani

回复

要查看或添加评论,请登录

Arpit Bhayani的更多文章

  • The Ideal End To An Ideal Career

    The Ideal End To An Ideal Career

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    2 条评论
  • How to Find and Ride the Next Tech Wave

    How to Find and Ride the Next Tech Wave

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    6 条评论
  • Engineer or Manager? How to Decide Your Path

    Engineer or Manager? How to Decide Your Path

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    5 条评论
  • One Career Bet Worth Taking

    One Career Bet Worth Taking

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    5 条评论
  • Leave your job with grace and gratitude

    Leave your job with grace and gratitude

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    7 条评论
  • Turn Boring Projects into Opportunities

    Turn Boring Projects into Opportunities

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    1 条评论
  • When is the right time to switch?

    When is the right time to switch?

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    8 条评论
  • Ramping up faster in your new job

    Ramping up faster in your new job

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    4 条评论
  • Back Your Disagreement with Data

    Back Your Disagreement with Data

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    2 条评论
  • Doubt yourself every day

    Doubt yourself every day

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    9 条评论

社区洞察

其他会员也浏览了