The new HTTP QUERY method explained
6 hours ago
- #Web Development
- #API Design
- #HTTP Methods
- RFC 10008 defines the new HTTP QUERY method, which is similar to GET but allows a request body for complex queries.
- GET requests with query parameters face issues with complex filters, such as long URLs, encoding overhead, logging concerns, and inconsistent array/nesting handling.
- Using GET with a request body is discouraged due to inconsistent client/proxy/server handling and potential compatibility issues.
- POST is a workaround for sending request bodies but is semantically problematic as it's non-idempotent and not read-only, affecting caching and retries.
- QUERY is designed to be safe and idempotent, enabling caching (with request body as part of the cache key) and proper support for complex searches.
- Adoption of QUERY is limited; consider existing GET parameters if sufficient, and avoid QUERY for shareable/bookmarkable links.
- Implementing caching for QUERY is more complex than for GET due to the need to incorporate the request body.