The new HTTP QUERY method explained

(kreya.app)

90 points | by CommonGuy 4 hours ago ago

45 comments

  • ramon156 25 minutes ago

    "QUERY is just GET"

    "Using GET with a Body works"

    Seems like this is going everyone's head. You're not supposed to use GET with a Body, this is a hack, therefore having an explicit method makes sense.

    Just because it works, doesn't mean its the right way

    • dotancohen 11 minutes ago

        > Just because it works, doesn't mean its the right way
      
      Tell that to anybody in the business long enough to decipher someone else's Perl!
  • tosti an hour ago

    > using HTTP GET with a request body is a bad idea, as for example users behind a corporate firewall or a different browser may be unable to use your website.

    So is using QUERY requests for quite some time from now.

    • jy14898 an hour ago

      405 Method Not Allowed is trivial to fall back to POST. How do you know the GET request behaved incorrectly?

      • tosti 41 minutes ago

        That's assuming the corporate proxy is well-behaved.

    • jbverschoor an hour ago

      Yeah, query seems just GET with a body. No difference in protocol nor behavior

      • gl-prod 22 minutes ago

        The difference is the method. Query you're saying I can use body. GET you should never use body.

      • ComodoHacker an hour ago

        Except compatibility. If you're using classic GET and it's enough for you, you aren't affected.

        • 4gotunameagain 15 minutes ago

          What is compatible with a QUERY but not with a GET ?

          • dotancohen 10 minutes ago

            Intermediate proxies, caches, CDNs, firewalls, and load balancers.

  • IshKebab 3 minutes ago

    What are the chances sites start using this to prevent sharing links...

  • ktpsns 3 hours ago

    HTTP QUERY was discussed many times in the past here:

    https://news.ycombinator.com/item?id=48568502 (4d ago, 173 comments)

    https://news.ycombinator.com/item?id=29794838 (4y ago, 125 comments)

  • waweic an hour ago

    I wonder what the drawbacks of standardizing a GET body would have been. CoAP already has it (which creates friction in building CoAP<->HTTP proxies).

    All in all, I dislike the overall focus on the HTTP method when designing "RESTful" interfaces. If all we're building is, effectively, an RPC, why would the cacheability meta-information be the first thing we specify?

  • Rapzid 34 minutes ago

    Body is already optional with GET. Proxies aren't supposed to touch it or assign meaning to it; it's between the client and the end server.

    A whole new method whose semantics don't really fit with the others is.. An odd way forward.

    • CommonGuy 25 minutes ago

      Proxies are allowed to drop bodies of HTTP GET requests.

      RFC 9110 states:

      > [..] content received in a GET request has no generally defined semantics, cannot alter the meaning or target of the request [..]

      > A client SHOULD NOT generate content in a GET request [..]

    • juliangmp 27 minutes ago

      Yeah I always disliked that there's this idea that you can't put a body on a GET request. Iirc openapi generators goes out of its way to not support that which has lead to me writing a small rant into an API specification before to explain why the get_xyz uses POST...

    • thewisenerd 20 minutes ago

      semantics become extremely relevant when "proxies" start caching.

  • 8-prime 2 hours ago

    It's interesting to see additions to HTTP methods as it much feels like the existing ones are set in stone. At least for the time that I have been a developer. I'm curious to see how fast the adoption/support for HTTP QUERY will be. I've had my fair share of situations where I wished for something like HTTP QUERY.

    • PunchyHamster an hour ago

      zero. Many libs will/can just request method as a string so you can start coding now

      > I've had my fair share of situations where I wished for something like HTTP QUERY.

      Using POST instead comes with no drawbacks

      • rezonant 18 minutes ago

        I think the article summarizes pretty well what the drawbacks of POST are: unclear idempotency (well it's actually pretty damned clear: they are not cacheable). That complicates caching logic, and that's not just for the application server itself, but any reverse proxies in front of it as well as the user agent itself.

        I'm not sure QUERY is a great solution, because in the context of a web application absolutely no one enjoys using a page that does not keep its state on refresh, so that really limits where QUERY makes sense, but if you have a case that is not driven by navigation, great.

    • hparadiz an hour ago

      I can implement it in about 10 minutes. Not even kidding.

      • echoangle an hour ago

        In what role? As a user writing client code or when implementing the caching middleware or the Webserver?

        • hparadiz an hour ago

          In my CRUD controller that I already have.

  • doctor_phil an hour ago

    Nice, not having bodies on GET has been a pet peeve of mine for a long time. It would be nice to allow bodies on DELETE as well, but that is less of a problem in most cases.

  • nokeya an hour ago

    If it needs so much explanation and discussion, maybe it is not a great idea after all?

    • flyingshelf 18 minutes ago

      Arguably the only explanation you need is that "QUERY is the same as GET plus a body". The article just explains what GET is and isn't, but that can be implied.

    • reddalo an hour ago

      The article describes the current situation first. The whole explanation is quite simple: QUERY requests are the same as GET, but they have a body.

    • IshKebab 4 minutes ago

      It doesn't really need that much explanation though. TL;DR: It's GET but with bodies officially supported.

  • koolala 2 hours ago

    What do you think people will make the Query request body? Most everything will use this for JSON but it could be anything so what other interesting things do you think will go in there? Query 1 + 1 and get 2?

    • miggol an hour ago

      Considering the guideline that QUERY should be idempotent and cacheable, file querying requests come to mind. Reverse image search, for example.

    • dreambigwrkhard 2 hours ago

      I'm curious too. Unless the developer is really passionate about this I don't think a dev will risk (potential) compatibility issues or unexpected footguns to use this when the workarounds do seem to work quite well already. I just dont see the benefit but maybe it's because I am just not aware of a real world use case; happy to be corrected.

      • unilynx an hour ago

        Elastic/Opensearch uses GET requests with a body for search, which is complicated or forbidden (not exactly sure) with the HTTP spec. Not all HTTP clients are willing to submit a body with a GET.

        So opensearch also allows you to POST search requests, but those are uncacheable

        QUERY would fit here perfectly - it's probably trivial for opensearch to add but it will take some time for clients to catch up.

  • grugdev42 an hour ago

    We should have just added optional body support for GET requests.

    So much simpler...

  • marc_vuit 23 minutes ago

    nice man

  • hparadiz 3 hours ago

    This feels like someone coming up with XML when JSON already exists.

    • flanked-evergl 2 hours ago

      No, it does not feel like that.

      • hparadiz 2 hours ago

        My framework is already two decade old prior art and you still haven't actually convinced me that this RFC solves a problem.

        • rmunn an hour ago

          1. Sometimes you need a request body. 2. POST cannot be guaranteed to be safe if re-sent. 3. This is GET with a request body, guaranteed* to be safe if re-sent.

          * With the caveat that it's only guaranteed if the server is following the RFC correctly.

          • PunchyHamster an hour ago

            > POST cannot be guaranteed to be safe if re-sent.

            It can absolutely be guaranteed. What it can't be is communicated to be safe so browser gonna ask its silly question

          • LaGrange an hour ago

            I will keep using POST and not some weird thing that isn’t supported by a proxy living in the basement of a shoe store in Wageningen or whatever.

          • hparadiz an hour ago

            I read the RFC front to back. It is lazy. To the point where I'd be embarrassed to even show it to people.

            For one you would never allow a client to dictate the query. That is a security and validation problem. So you have to deconstruct the query anyway and then rebuild it. That's HTTP APIs 101. Now if the authors of this RFC knew what they were doing they could enforce trust with some sort of JWT like trust mechanism but no they don't bother to define ANYTHING like that. Instead and I will quote this for completeness because it's honestly one of the funniest things I've ever read in an RFC.

            > 4. Security Considerations

            > It can be used as an alternative to passing request information in the URI (e.g., in the query component). This is preferred in some cases, as the URI is more likely to be logged or otherwise processed by intermediaries than the request content. In other cases, where the query contains sensitive information, the potential for logging of the URI might motivate the use of QUERY over GET.

            This. This is just plain baffling to me. The argument is that QUERY replaces GET (it doesn't) so let's shove data into the same place that POST already does because it MAY MAY be logged. Bro the people doing the logging are logging the entire damn thing URI, Header, and Body. What even is this.

            And again if they knew their shit they would know that GET has a soft cap of 2,083 characters from the internet explorer days so no one shoves more than that into a url for compatibility and if they do they risk losing data so they use POST anyway. Heck my framework even does JSON post bodies in the POST. And again if you are writing an RFC do your research and use this technical fact as an advantage. Define your own limits and explain why based on existing methodology. It would actually give your RFC some weight.

            It doesn't even bother to address query feedback errors like what if the disk says no and writes are locked.

            Frankly...... I miss the old days when RFCs where measured in pounds of paper.

            • flanked-evergl an hour ago

              > For one you would never allow a client to dictate the query. That is a security and validation problem. So you have to deconstruct the query anyway and then rebuild it.

              Every single SQL server allows a client to dictate the query. Furthermore, not all queries are SQL queries.

              • hparadiz an hour ago

                Yes. That's why you connect to the server instead of some random third party. lmao.