• HTTP
  • APIs
  • web standards
  • Node.js

The HTTP QUERY method (RFC 10008): a safe search with a request body

A beginner's explainer of RFC 10008: why long searches don't fit in GET URLs, how QUERY differs from GET and POST, what Location, 303 and Accept-Query mean, and a Node.js server and client tested with curl and fetch, including a curl redirect trap.

Imagine you are building a search page for an online shop. The user ticks twelve brands, three price ranges, five colours and a sort order. If you put all of that in the address, the URL becomes hundreds of characters long, ends up in server logs and browser history, and may hit a length limit somewhere between the browser and your server. So most teams switch to POST /search with a JSON body. That works, but now nothing in the request says “this is only a read”. A proxy cannot reuse a stored response for the next identical search, and an HTTP client should not retry it on its own after a dropped connection, because a repeated POST might create a second order.

In June 2026 the IETF published RFC 10008, “The HTTP QUERY Method”, a Standards Track specification that fills exactly this gap. QUERY carries the search in the request body, like POST, but promises that the request is read-only and safe to repeat, like GET. This article explains what that promise means, what the new response headers do, and how to try QUERY today with a small Node.js server. Every command below was run on Node.js 22.23.5 and curl 8.5.0 on Linux.

A few terms first

  • HTTP method: the verb at the start of a request (GET, POST, PUT, …). It tells the server what kind of action the client wants.
  • Request body (content): data sent after the headers, such as a JSON document. In RFC 10008 the body of a QUERY request is called the query content.
  • Safe method: a method the client uses only to read. RFC 9110, section 9.2.1 says safe methods have “essentially read-only” semantics: the client does not request or expect any state change on the server.
  • Idempotent method: sending the same request twice has the same intended effect as sending it once (RFC 9110, section 9.2.2). That is why clients may retry idempotent requests automatically after a network failure.
  • Media type: the Content-Type value that says what format the body uses, for example application/json.
  • Cache key: the information a cache uses to decide whether two requests are “the same” and can share a stored response. For GET this is mainly the URL.

Why GET and POST both fall short

RFC 10008 starts from the same problem as our shop. Its introduction lists four issues with putting a large query in the URL: size limits are not known ahead of time (RFC 9110 only recommends that software supports at least 8,000 octets), encoding data into a URL is inefficient, URLs are more likely than bodies to be logged or bookmarked, and every combination of inputs becomes a separate resource. RFC 10008, section 1

Two common workarounds both have problems:

  1. GET with a body. RFC 9110 gives content in a GET request no generally defined meaning, and the RFC 10008 comparison table repeats this: “no defined semantics”. Some servers, proxies and client libraries drop or reject it, so you cannot rely on it.
  2. POST with a body. It works everywhere, but POST is “potentially” unsafe and non-idempotent. In the RFC’s words, without specific knowledge of the server “it is not readily apparent … that a safe, idempotent query is being performed”.

QUERY sits between them. Here is the comparison from RFC 10008 in a shorter form:

Property GET QUERY POST
Safe yes yes potentially no
Idempotent yes yes potentially no
Request body no defined semantics expected expected
Cacheable yes yes only for later GET/HEAD
URI for the query itself yes, by definition optional (Location) no

How QUERY works

1. The body and its media type define the query

The server reads the body, interprets it according to Content-Type, and runs the query within the scope of the target URL. The RFC is strict about the media type: “Servers MUST fail the request if the Content-Type request field … is missing or is inconsistent with the request content.” A server is not allowed to guess the format from the bytes (“content sniffing”). RFC 10008, section 2 · section 2.1

Section 2.1 also suggests status codes for each failure, which gives you a ready-made error design:

Situation Suggested status
No Content-Type at all 400 Bad Request
A media type the resource does not support for QUERY 415 Unsupported Media Type
Content-Type does not match the actual body 400 Bad Request
Well-formed query that cannot run (for example, a valid SQL query naming a table that doesn’t exist) 422 Unprocessable Content
The client’s Accept asks for a response format you can’t produce 406 Not Acceptable

2. Safe and idempotent, with one nuance

QUERY is safe and idempotent, so a client can repeat it “after a connection failure”. “Safe” is about what the client asks for. RFC 9110 notes that the server may still do things the client did not ask for, such as writing logs (section 9.2.1), and RFC 10008 allows it to create a new URL that points to the query or its result, as the next step shows. RFC 10008, section 2

3. Optional URLs for later GET requests

A good web design gives important things their own URL. QUERY keeps that possible with two existing response headers:

  • Location in a 2xx response points to the equivalent resource: a URL that, when fetched with GET, runs the same query again and returns current results. The client no longer needs to resend the body. Section 2.4
  • Content-Location points to the result you just received, frozen as it was. Section 2.3

Both URLs may be temporary. If a later GET fails, the client goes back to the original QUERY.

4. Redirects keep the method, except 303

Section 2.5 says that after 301, 302, 307 or 308 the client can repeat the QUERY, with the same body, at the new URL. The old browser habit of turning a redirected POST into a GET after 301 or 302 does not apply to QUERY. A 303 See Other is different: it tells the client to fetch the Location URL with a plain GET. A server can use 303 when it only wants to hand out a stored-query URL without sending results.

5. Caching uses the body

Responses to QUERY are cacheable, but the cache key “MUST incorporate the request content” and related metadata such as the media type. A cache may normalise insignificant differences first, for example JSON whitespace. Section 2.7 This matters for you as an API owner: a cache that keyed QUERY responses on the URL alone would serve one user’s search results to another search.

6. Accept-Query advertises supported formats

The new response header Accept-Query lists the query formats a resource accepts, for example Accept-Query: "application/jsonpath", application/sql;charset="UTF-8". It uses the Structured Fields syntax from RFC 9651, so parse it with a structured-field parser rather than by splitting on commas. Section 3 Clients can also discover support with OPTIONS and the Allow header, or simply try QUERY and handle a 405 Method Not Allowed. Appendix A.2

Try it: a QUERY endpoint in Node.js

The goal is a contacts search that accepts a JSON query, follows the RFC’s status codes, and returns a Location for repeat searches. It uses only the built-in node:http module, whose parser already recognises the QUERY method on Node.js 22.23.5 (http.METHODS.includes('QUERY') returns true). If you are still choosing a Node.js line, see choosing between the Node.js 22, 24 and 26 LTS lines.

Step 1: write the server

Create an empty folder and save this as server.mjs:

// server.mjs — a tiny QUERY endpoint using only node:http
import http from 'node:http';
import { createHash } from 'node:crypto';

const contacts = [
  { surname: 'Smith', email: 'smith@example.org', city: 'Hanoi' },
  { surname: 'Jones', email: 'sally.jones@example.com', city: 'Da Nang' },
  { surname: 'Dubois', email: 'camille.dubois@example.net', city: 'Hanoi' },
];
const storedQueries = new Map(); // id -> parsed query

function runQuery(q) {
  return contacts.filter((c) => !q.city || c.city === q.city).slice(0, q.limit ?? 10);
}

const server = http.createServer(async (req, res) => {
  const url = new URL(req.url, 'http://localhost');

  if (url.pathname === '/contacts' && req.method === 'OPTIONS') {
    res.writeHead(204, { Allow: 'GET, HEAD, QUERY, OPTIONS', 'Accept-Query': 'application/json' });
    return res.end();
  }

  if (url.pathname === '/contacts' && req.method === 'QUERY') {
    const type = (req.headers['content-type'] ?? '').split(';')[0].trim();
    if (!type) {
      res.writeHead(400, { 'Content-Type': 'text/plain' });
      return res.end('Missing Content-Type\n');
    }
    if (type !== 'application/json') {
      res.writeHead(415, { 'Content-Type': 'text/plain', 'Accept-Query': 'application/json' });
      return res.end(`Unsupported query format: ${type}\n`);
    }
    let body = '';
    for await (const chunk of req) body += chunk;
    let q;
    try { q = JSON.parse(body); } catch {
      res.writeHead(400, { 'Content-Type': 'text/plain' });
      return res.end('Body is not valid JSON\n');
    }
    if (q.city !== undefined && typeof q.city !== 'string') {
      res.writeHead(422, { 'Content-Type': 'text/plain' });
      return res.end('"city" must be a string\n');
    }
    // A stable id from the normalized query, so the same query gets the same URI.
    const id = createHash('sha256').update(JSON.stringify({ city: q.city, limit: q.limit })).digest('hex').slice(0, 12);
    storedQueries.set(id, q);
    if (url.searchParams.has('indirect')) {
      res.writeHead(303, { Location: `/contacts/stored-queries/${id}` });
      return res.end();
    }
    res.writeHead(200, { 'Content-Type': 'application/json', Location: `/contacts/stored-queries/${id}` });
    return res.end(JSON.stringify(runQuery(q)) + '\n');
  }

  const m = url.pathname.match(/^\/contacts\/stored-queries\/([0-9a-f]{12})$/);
  if (m && req.method === 'GET') {
    const q = storedQueries.get(m[1]);
    if (!q) { res.writeHead(404); return res.end(); }
    res.writeHead(200, { 'Content-Type': 'application/json' });
    return res.end(JSON.stringify(runQuery(q)) + '\n');
  }

  if (url.pathname === '/old-contacts') {
    res.writeHead(307, { Location: '/contacts' });
    return res.end();
  }

  res.writeHead(405, { Allow: 'GET, HEAD, QUERY, OPTIONS' });
  res.end();
});

server.listen(3000, () => console.log('Listening on http://localhost:3000'));

What each part does:

  • The OPTIONS branch answers discovery requests with Allow and Accept-Query.
  • The QUERY branch checks the media type before reading the body, then returns 400, 415 or 422 as section 2.1 suggests.
  • The id is a hash of the normalised query (only the fields that matter, in a fixed order). Two searches that differ only in whitespace or key order get the same Location. This is the same idea as the cache-key normalisation in section 2.7.
  • ?indirect makes the server answer with 303 instead of results, and /old-contacts returns a 307 redirect, so we can test both redirect rules.

The storedQueries map lives in memory, so stored URLs disappear on restart. That is allowed: the RFC says these URLs “might be temporary”.

Step 2: start it

In one terminal, in the same folder:

node server.mjs

Expected output: Listening on http://localhost:3000. Leave it running.

Step 3: send requests with curl

In a second terminal. curl’s -X QUERY sets the method; --data sends the body.

curl -si -X OPTIONS localhost:3000/contacts

Expected (date lines trimmed): HTTP/1.1 204 No Content, Allow: GET, HEAD, QUERY, OPTIONS and Accept-Query: application/json.

curl -si -X QUERY localhost:3000/contacts \
  -H 'Content-Type: application/json' \
  --data '{"city":"Hanoi","limit":5}'

Expected: HTTP/1.1 200 OK, a header such as Location: /contacts/stored-queries/7b0c88ea5ce3, and a JSON array with Smith and Dubois. Now repeat the search with GET and no body, using the path from your own Location header:

curl -s localhost:3000/contacts/stored-queries/7b0c88ea5ce3

You get the same two contacts. Then check the error paths:

curl -si -X QUERY localhost:3000/contacts -H 'Content-Type: application/sql' --data 'SELECT 1'
curl -si -X QUERY localhost:3000/contacts -H 'Content-Type: application/json' --data '{"city":42}'
curl -si -X POST localhost:3000/contacts

Expected status lines, in order: 415 Unsupported Media Type (with Accept-Query: application/json), 422 Unprocessable Entity (Node.js still prints the older name for 422; RFC 9110 renamed it “Unprocessable Content”) and 405 Method Not Allowed with an Allow header.

Step 4: send QUERY from JavaScript with fetch

Node’s built-in fetch accepts custom method names such as QUERY. Save this as client.mjs and run node client.mjs while the server is running:

// client.mjs — send QUERY with fetch and follow redirects
const base = 'http://localhost:3000';
const query = JSON.stringify({ city: 'Hanoi', limit: 5 });
const headers = { 'Content-Type': 'application/json' };

let res = await fetch(`${base}/contacts`, { method: 'QUERY', headers, body: query });
console.log('direct  :', res.status, res.headers.get('location'), await res.text());

res = await fetch(`${base}/contacts?indirect`, { method: 'QUERY', headers, body: query });
console.log('303     :', res.status, res.url, await res.text());

res = await fetch(`${base}/old-contacts`, { method: 'QUERY', headers, body: query });
console.log('307     :', res.status, res.url, await res.text());

All three lines print status 200 and the same two contacts. The interesting part is res.url, the final URL after redirects:

  • After the 303, fetch ended at /contacts/stored-queries/…. Our server only answers GET there, so fetch must have switched to GET, as section 2.5 describes.
  • After the 307 from /old-contacts, fetch ended at /contacts and got results, so it re-sent QUERY with the body. We also changed the 307 to a 302 in a separate test and fetch still kept QUERY, matching the rule that the POST-to-GET exception does not apply.

Common mistakes

  1. Following redirects with curl -L -X QUERY. -X forces the method on every request curl sends, including redirects. In our test, curl -L -X QUERY 'localhost:3000/contacts?indirect' … followed the 303 with QUERY and got 405 from the stored-query URL. With curl, follow a 303 yourself: read Location and send a separate GET.
  2. Treating QUERY like POST on the server. If your handler writes to the database, it breaks the safety promise, and clients or proxies may legitimately repeat it. Keep side effects to things the client did not ask for, such as logs or the stored-query URL.
  3. Guessing the media type. Accepting a body without Content-Type, or “detecting” JSON, goes against section 2.1. Reject it with 400 and tell the client what you accept.
  4. Caching by URL only. Every QUERY to /contacts has the same URL. Any cache in front of your API, including one you write yourself, must include the body and media type in the key, or it will mix up results. If you are not sure what an existing proxy or CDN does with QUERY, do not mark the responses as cacheable until you have tested it.
  5. Putting secrets back into URLs. QUERY helps keep sensitive search terms out of URL logs, but if your Location URL copies those terms, they leak again. The RFC says such URLs “SHOULD” not include sensitive parts of the request. Section 4 Our example uses a hash.

Limits: what to check before you adopt it

  • Browsers need CORS preflight. QUERY is not a CORS-safelisted method, so a cross-origin fetch with QUERY triggers a preflight OPTIONS request first. Your server must answer it and list QUERY in Access-Control-Allow-Methods. Section 4
  • The path is only as good as its weakest hop. A new method has to pass through every load balancer, WAF, API gateway and framework router between client and server. Some block unknown methods or drop their bodies. This article only tested Node.js and curl directly, with nothing in between; test your real chain before switching public clients.
  • HTML forms can’t send it. A form’s method attribute only supports GET and POST (plus dialog), so QUERY is for JavaScript clients, mobile apps and server-to-server APIs.
  • Keep a fallback. During the transition, many APIs can accept both POST /search and QUERY /search, with the same handler, and let clients move over gradually.
  • Short queries still belong in GET. The RFC’s own examples note that if a query is really short, “it is likely better to use GET”. A GET URL is easier to share, bookmark and cache.

Retries are also why safe methods matter elsewhere in HTTP. Our article on the NGINX TLS early-data flaw explains that requests sent as TLS 0-RTT early data can be replayed, which is only harmless for requests that are safe to repeat.

How to verify your own endpoint

Before you rely on a QUERY endpoint, check these things against a staging environment:

  1. OPTIONS returns Allow including QUERY, and Accept-Query lists the formats you actually parse.
  2. A QUERY without Content-Type returns 400, an unsupported type returns 415, and a well-formed but invalid query returns 422.
  3. Sending the same QUERY twice returns the same results and changes no data. Compare database row counts or audit logs before and after.
  4. The Location URL works with GET and contains no sensitive query terms.
  5. A QUERY sent through your real proxy or gateway reaches the app with its body intact. Log the received method and body length at the app.
  6. If anything caches the responses, two different bodies to the same URL return different results.

Conclusion

RFC 10008 gives a name and clear rules to something many APIs already did with POST: a read-only search with a body. Use QUERY when the query is too large or too sensitive for a URL. In return, follow its rules: require a correct Content-Type, keep the handler free of requested side effects, include the body in any cache key, and remember that 303 means “switch to GET”. Start with one internal endpoint, test it through your real proxies, keep the POST route as a fallback, and add a Location URL when users will want to repeat or share the search.

Written by Duy Pham Independent developer. I build the apps on this site and write about how they work.

More about me