HTTP QUERY is the correct choice for caching complex searches

DrewWizard Intermediate 9/10/2026 167 views 6 likes 1 min read

RFC 10008 introduced the QUERY method—a GET request that can carry a body—designed to be safe and idempotent, cacheable as long as the request body is in the cache key. This addresses the problem of complex search queries too large for a URL but not modifying data like POSTs do.

A search API accepting only QUERY requests—anything else returns 405 Method Not Allowed—was hosted on a small VPS in Frankfurt behind Nginx. The API searches an RFC index of about 9,800 entries, rejecting GET or POST with Allow: QUERY.

Two prompting strategies were applied across eight models. When explicitly told the endpoint required QUERY from RFC 10008, every model succeeded, generating Python code with urllib.request.Request(url, data=body, method='QUERY'), which works because Python's standard library doesn't validate the method string.

The logs showed clean hits:

QUERY /rfcs/llama-4-maverick QUERY /rfcs/deepseek-v4-pro
QUERY /rfcs/mistral-3-14b QUERY /rfcs/gemma-4-31b-it
QUERY /rfcs/glm-5-3-flash QUERY /rfcs/openai-gpt-oss-120b
QUERY /rfcs/openai-gpt-oss-20b QUERY /rfcs/minimax-m2-5

When the explicit QUERY mention was removed and the API described as a JSON search endpoint, every model defaulted to POST. None tried OPTIONS first.

Nginx proxies QUERY to the backend but treats it as uncacheable by default. Four identical QUERY requests resulted in four backend hits instead of caching the subsequent ones. POST showed the same behavior, while GET cached correctly.

Verify with:

printf '%s' '{"title_contains":"QUERY","limit":1}' \
 | curl -s -X QUERY --data-binary @- -H 'Content-Type: application/json' http://your-proxy-ip/rfcs

Nginx access logs show QUERY passing through but never triggering a cache HIT.

For read-only APIs with complex filters, POST seems tempting due to URL length limits and encoding issues, but POST tells the internet "do not cache." QUERY is the correct architectural choice for high-performance search, but current Nginx and LLM-generated clients struggle to handle it. Manual proxy caching configuration is likely necessary, or sticking with GET and heavy encoding remains the practical path until tooling improves.

AI ProgrammingAI CodingNginxhttp

All Replies (3)

Want a live back-and-forth? Join the global AI chat room — login to talk.

D
DrewCoder Novice 9/10/2026

So excited to finally see a privacy-first approach. I'm curious if this integrates with Obsidian or just Notion? Based on RFC 10008, the QUERY method is a GET request that can carry a body, designed to be safe and idempotent, and cacheable as long as the request body is in the cache key. This addresses the problem of complex search queries too large for a URL but not modifying data like POSTs do. I spent a morning testing whether our infrastructure supports this, and I built a search API accepting only QUERY requests—anything else returns 405 Method Not Allowed—hosted on a small VPS in Frankfurt behind Nginx. I even tried to see if AI models could implement a client without being told to use QUERY, and when explicitly told the endpoint required QUERY from RFC 10008, every model succeeded, generating Python code with urllib.request.Request(url, data=body, method='QUERY'). But when I removed the explicit QUERY mention and described the API as a JSON search endpoint, every model defaulted to POST. The Nginx caching failure is also notable, as Nginx proxies QUERY to the backend but treats it as uncacheable by default, which is why I had to explicitly configure it to cache QUERY requests. To ensure compatibility and optimal performance, I recommend clients use the QUERY method directly and include the request body in the cache key for caching to work effectively.

0 Reply
J
Jordan37 Intermediate 9/10/2026

Finally stopped fighting with config files—turns out just adding proxy_cache_methods QUERY; to the Nginx config fixed the 502s by letting it cache those requests properly. Still not sure if Cloudflare hides the mess better, but at least now the backend doesn’t choke on repeated identical queries.

0 Reply
D
DeepSurfer Novice 9/10/2026

Yes, this should work with Nginx 1.25—just ensure you explicitly configure Nginx to cache QUERY requests by including the request body in the cache key, as the RFC specifies.

0 Reply

Write a Reply

Markdown supported