Stop Using POST for Search Queries: Enter HTTP QUERY
The New HTTP QUERY Method: Finally, a Proper Way to Send Complex Requests
If you’ve been building RESTful APIs for the last decade, you’ve lived by a strict set of rules. You fetch data with GET, create entities with POST, update with PUT, and delete with DELETE. The HTTP method tells the server exactly what your intention is.
But recently, a new Request for Comments was published: RFC 10008, which officially defines the QUERY method for HTTP.
If your first reaction is, "Wait, why do we need a new HTTP method? Can't we just use what we already have?" , you aren't alone. This exact question has sparked massive debates in Hacker News ( Lowkey fun to read 😼)
Let’s break down why the QUERY method exists, the messy workarounds we’ve been forced to use, and what this means for the future of API design.
The Problem: When GET Just Isn't Enough
Traditionally, if you wanted to filter a resource, you used query parameters in a GET request: GET /api/v1/users?role=admin&status=active&sort=desc
This works beautifully for simple filters. But what happens when you need to perform complex relational queries, deep nesting, or pass an array of 500 specific IDs?
Suddenly, you run into a wall of issues:
URL Length Limits: Browsers and servers have maximum character limits for URLs. Massive queries will just get truncated or rejected.
Encoding Nightmares: Sending non-ASCII or special characters requires URL encoding, bloating the request size.
Inconsistent Arrays: How do you represent an array in a URL? Is it
?roles[]=admin&roles[]=reporter,?roles=admin&roles=reporter, or?roles=admin,reporter? It’s entirely implementation-specific.Security & Logging: URLs are logged everywhere (proxies, web servers, browser history). You definitely don't want sensitive filtering criteria or massive payloads sitting in plaintext logs.
The Two Workarounds Everyone Tries
Since GET falls short for complex queries, developers have historically relied on two workarounds. Both come with heavy compromises.
Workaround 1: GET with a Request Body
From a purely theoretical standpoint, older HTTP RFCs didn't explicitly forbid a body in a GET request. So, developers tried it.
Why it’s a bad idea: The ecosystem hates it. Proxies, corporate firewalls (WAFs), and even CDNs like AWS CloudFront will often silently strip the body off a GET request or reject it outright.
Furthermore, the browser's native fetch API doesn't even support sending a body with a GET request.
And then I read the comment that changed my perspective:
A GET request with a body is an attack-shaped design flaw*. It blurs the lines of request validation and opens the door to request smuggling attacks.*
Workaround 2: Using POST for Everything
Since GET with a body is blocked, the standard workaround is to use POST. After all, POST allows request bodies .
Why it’s a bad idea: Semantics. POST is defined as non-safe and non-idempotent. It is meant for creating resources or triggering state-changing processes.
Because POST is non-idempotent, CDNs and reverse proxies will not cache it by default. If you use POST for a read-only search query, you lose all the performance benefits of edge caching. You also lose the ability to safely auto-retry failed requests without worrying about side effects.
The crazy part ? Because GraphQL uses POST for all its queries, CDNs like Cloudflare have to use hacky workarounds—like creating a fake GET request under the hood just to cache GraphQL responses!
Enter the Hero: HTTP QUERY
To finally solve this long-standing problem , RFC 10008 introduces the QUERY method.
The spec is straightforward: QUERY is exactly like GET, but it officially supports a request body.
QUERY /api/v1/users/search HTTP/1.1
Content-Type: application/json
{
"role": "admin",
"departments": ["engineering", "product"],
"filters": {
"active_since": "2023-01-01"
}
}
Why QUERY is a Game Changer
It is Safe and Idempotent: Just like
GET, making aQUERYrequest does not change the state of the server. You can retry it safely.It is Cacheable: Because it is idempotent, proxies and CDNs can cache it.
Semantic Clarity: Middleboxes now have concrete guidance. They know this request is read-only, but carries a payload.
No URL Limits: You can send massive, deeply nested JSON payloads without worrying about URL character limits.
The Comment Section Had Some Strong Opinions.
While QUERY sounds perfect on paper, the Hacker News community has pointed out some very real-world hurdles , we are going to face during adoption.
1. The Caching Normalization Problem
CDNs and proxies terminate TLS, meaning they cam read the request body to cache it.
But how do you generate a cache key from a JSON body?
If Client A sends {"a": 1, "b": 2} and Client B sends {"b": 2, "a": 1}, those are semantically the exact same query. But as raw strings, they are different.
Proxies will need to implement complex JSON Normalization to ensure they aren't caching the same query multiple times just because the keys were ordered differently.
2. The Legacy Infrastructure Wall
Just because the RFC is published doesn't mean the internet is ready.
WAFs and Proxies: Many enterprise firewalls are configured to only allow a strict whitelist of HTTP methods (
GET,POST,PUT,DELETE). They will likely rejectQUERYwith a405 Method Not Allowed.Old Servers: Some ancient, unpatched proxy appliances might not know how to parse an unknown verb and could crash or drop the connection.
Updating the spec is easy; updating millions of unattended black-box routers and legacy enterprise proxies will take years.
3. Goodbye, Link Sharing
One of the best features of GET is that the entire state of the request is in the URL. You can copy the URL, bookmark it, or email it to a colleague, and they will see the exact same filtered data.
Because QUERY relies on a request body, you cannot share a QUERY URL. If your users rely on bookmarking search results or sharing filtered views via URL, you must stick to GET.
So, Should You Use QUERY Today?
The short answer is: Probably not yet, but you should prepare for it.
Support for HTTP QUERY is still in its infancy. API clients, major browsers, and enterprise proxies need time to update their firmware and software to recognize and properly handle the new verb.
However, there are massive use cases that will benefit immensely once the ecosystem catches up:
GraphQL: APIs could finally use
QUERYfor read operations (allowing for proper edge caching) and reservePOSTstrictly for mutations.Search Engines: Tools like ElasticSearch and OpenSearch, which currently suffer from the
GETvsPOSTdilemma for complex search payloads, will have a native, semantically correct HTTP method.Complex Dashboards: Internal tools that rely on heavy, nested filtering can finally send clean JSON bodies without hacking together
POSTrequests.
The One Rule That Matters
Stick to
GETif your filters are simple and you want your URLs to be shareable and easily cacheable.Use
QUERYfor complex, read-only searches that require a JSON body, provided you have tested that your intermediate proxies and CDNs won't block it.Never use
GETwith a body. It’s a hack that will eventually break.Stop using
POSTfor read-only queries. It ruins your caching strategy.
The web is finally getting a tool designed specifically for the complex, data-heavy applications we build today. It might take a few years for the dust to settle, but HTTP QUERY is a welcome addition to the RESTful toolkit.
Comments
Join the discussionNo comments yet. Be the first to comment.