Agent Wranglers

API-26Optional

Search with QUERY when the filter outgrows the address

Send a search that is too long for query parameters, or that holds personal data, in the body of a QUERY request. Never send it as a GET with a body.

How to do it

RFC 10008 defines QUERY as safe and idempotent, like GET, so clients may retry it after a dropped connection. The search travels in the body, which servers and proxies log less often than addresses. That keeps search terms out of logs, as Keep secrets out of addresses asks. List the body types you accept in the Accept-Query header. Answer 400 when Content-Type is missing, and 415 with Accept-Query for a type you don't accept. Answer 422 when the body parses but the search can't run. Send Location when the same search can be fetched again with GET. Keep plain parameters for short filters. A proxy, CDN, firewall or HTTP library that predates RFC 10008 may refuse an unknown method with 405 or 501, or pass it on uncached. Send a test QUERY through every layer in front of the API before you publish it. Keep a POST search endpoint as a fallback until each layer passes it.

Examples

HTTP example

QUERY /orders HTTP/1.1
Content-Type: application/json
Accept: application/json

{"customerEmail":"anna@example.com","status":["paid","shipped"],"limit":50}

HTTP/1.1 200 OK
Content-Type: application/json
Accept-Query: application/json

{ "items": [ ... ], "nextCursor": "b3JkXzlhMXo" }

JavaScript example

const response = await fetch('https://api.example.com/orders', {
  method: 'QUERY',
  headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
  body: JSON.stringify({ customerEmail: 'anna@example.com', status: ['paid', 'shipped'], limit: 50 }),
})

Python example

import httpx

response = httpx.request(
    "QUERY", "https://api.example.com/orders",
    headers={"Authorization": f"Bearer {token}"},
    json={"customerEmail": "anna@example.com", "status": ["paid", "shipped"], "limit": 50},
)

How to check

Send the same QUERY /orders with a JSON body twice. Both answers are 200 with the same items, and no stored data changed. The request without Content-Type gets 400, and one sent as text/plain gets 415 with Accept-Query. The same QUERY sent through the public hostname, past the CDN and proxy, gets the same 200.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/lists/query-method">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.