TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Using HTTP GET with request body

8 pointsby larryfreemanalmost 6 years ago
We are doing a RESTful service that is non-public. For a request that is read-only and potentially uses 20+ parameters, we are planning to implement it as a GET request that will pass these parameters in the body.<p>I have seen the well known announcement by Dropbox in 2015: https:&#x2F;&#x2F;blogs.dropbox.com&#x2F;developers&#x2F;2015&#x2F;03&#x2F;limitations-of-the-get-method-in-http&#x2F; and the response in Hacker News: https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9133469<p>As I understand it, there are three potential issues with a GET with request body:<p>(1) Not all servers will support this.<p>(2) Not all tools will support this (POSTMAN added support this year: https:&#x2F;&#x2F;github.com&#x2F;postmanlabs&#x2F;postman-app-support&#x2F;issues&#x2F;131)<p>(3) There is not yet a consensus on GET with request body. (For example, is Dropbox still using a POST)<p>I am not finding too many recent statements about this, I wanted to open up the question here and see what the current opinions are.<p>I heard that ElasticSearch is using GET request parameters in the body. It sounds like there are some who are against this approach: https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;36939748&#x2F;elasticsearch-get-request-with-request-body<p>(1) Does this make sense for a private server? (The answer here seems to be yes -- unless I am missing something)<p>(2) Does this make sense in general? If the tools needed support it, what is wrong with implementing a RESTful service that requires GET request parameters in the body?

9 comments

amirathialmost 6 years ago
I&#x27;d recommend sticking to POST requests with body that fetches the data you need. I know it&#x27;s semantically odd because the POST request not creating a &quot;resource&quot; on the server. But it&#x27;s practically very useful as it&#x27;ll work well with client libraries, load balancers etc.<p>You can get some inspiration from GraphQL for your use case. All GraphQL queries are POST requests with body specifying what data the client needs.
评论 #20652196 未加载
dmlittlealmost 6 years ago
While there&#x27;s nothing stopping you from doing so I would be wary about it. Even though the service will be internal you might still need to use third-party software&#x2F;tools in the future that will be incompatible because of this.<p>For example, will you need to use a 3rd party request library? Will you need to set up some sort of proxy (NGINX, HAProxy, etc.)? Will you need to use a cloud load balancer (I&#x27;m not sure if they would send a request payload for GET requests)?<p>For open-source solutions you might be able to fork them to add this behavior but why do so to begin with? Is there a specific reason why you don&#x27;t want to use query parameters?
评论 #20611451 未加载
AnotherIdiotalmost 6 years ago
If you need to have lots of query parameters (I&#x27;m assuming that&#x27;s what you&#x27;re referring to) then something is wrong in your design. Start by dividing your problem into simpler parts and go from there.<p>A dumb idea would be to encapsulate various options into a single query parameter. Compressing query parameter&#x27;s names and values and encoding them in base64 (or some other base of your choice) might also help. But all of this will just add tons of needless complexity to it.<p>Do you really <i>NEED</i> 20+ query parameters?<p>I am curious, though. What are you actually trying to achieve here?
评论 #20611470 未加载
zzo38computeralmost 6 years ago
I think that only request methods that can use a request body can use a request body. (However, it is only private use, then might not matter.)<p>One alternative way is to use a different protocol rather than HTTP, if that is applicable for your use. Another way is to make up a new LONG_GET method.
评论 #20611481 未加载
tomohawkalmost 6 years ago
Convention should always be adhered to unless you have a really good reason for not doing so. This is especially true for things like REST where convention is the whole point.
icedchaialmost 6 years ago
Keep it simple and just use a POST. Sure, you&#x27;re read only, but using a request body with a GET is &quot;weird&quot; and non-standard.
评论 #20611486 未加载
fabioyyalmost 6 years ago
RFC of http protocol allows body content on GET.
quickthrower2almost 6 years ago
Another idea. PUT the list of ids and get an ID to that “blob” and in a second request do a GET with the blob ID.
echeesealmost 6 years ago
I think you should be wary of doing this - it may do weird things with a cache
评论 #20611497 未加载