Repository navigation
feat(router): add support for the QUERY HTTP method - #140
Open
DavideCarvalho wants to merge 2 commits into
Open
DavideCarvalho wants to merge 2 commits into
DavideCarvalho wants to merge 2 commits into
Conversation
Member
|
@DavideCarvalho Thanks for the PR. Can you please also send another PR for the docs covering this method. Since, QUERY is a new method, it will nice to share a tight summary of what this method is supposed to be used for and then maybe link to the spec or an article that covers it in a detail |
Member
|
Hey @DavideCarvalho! 👋🏻 On top of what Aman said, we need to also update RFC 10008 also requires the server to reject |
Member
|
Any news @DavideCarvalho? |
Author
|
Hey sorry, working on it today! |
Adds a router.query() shorthand for defining routes that respond to the QUERY HTTP method (draft-ietf-httpbis-safe-method-w-body), along with urlFor.query() and signedUrlFor.query() builders for parity with the other verb-specific helpers. Node.js supports the QUERY method since llhttp shipped it, which is included in every version covered by the engines range (>=24.0.0). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
RFC 10008 (section 2) requires servers to fail QUERY requests when the Content-Type request header is missing, since the request content and its media type together define the query. Section 2.1 recommends a 400 response for requests lacking media type information. The route finder now raises E_INVALID_QUERY_CONTENT_TYPE (400) for a matched QUERY route when the Content-Type header is missing or is not a valid media type. The check runs before the route middleware (including the bodyparser), so the request content is never read, and the error flows through the app error handler like E_ROUTE_NOT_FOUND. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DavideCarvalho
force-pushed
the
feat/query-http-method
branch
from
October 16, 2026 13:29
4a6099f to
cfbb1cc
Compare
This was referenced Oct 16, 2026
Author
|
Thanks for the patience! Updated:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds first-class support for the
QUERYHTTP method (RFC 10008), the safe, idempotent method that carries the query in the request body. It is meant for complex queries that don't fit in a URL.router.query(pattern, handler)shorthand, following the exact same pattern asrouter.get/post/put/patch/deleteurlFor.query()on the URL builder (runtime + type definitions inclient/types.ts)signedUrlFor.query()on the signed URL builderContent-Typeenforcement: a matchedQUERYroute fails withE_INVALID_QUERY_CONTENT_TYPE(400) when theContent-Typeheader is missing or isn't a valid media typerouter.any()was intentionally left unchanged to avoid altering the behavior of existing routes.Why
Node.js parses the
QUERYmethod out of the box on every version covered by this package's engines range (>=24.0.0; llhttp has shipped it since before v24.0.0, verified againstdeps/llhttpat thev24.0.0tag), so routes defined withrouter.route(pattern, ['QUERY'], handler)already work today. This PR givesQUERYthe same ergonomic, type-safe API as the other verbs.RFC 10008 §2 says servers MUST fail the request if the
Content-Typeis missing or inconsistent with the content, and §2.1 recommends400for requests that lack media type information. The check runs in the route finder after a route matches and before the route middleware runs. So unknown routes still return404, the bodyparser never reads the content of a rejected request, and the error goes through the app's error handler likeE_ROUTE_NOT_FOUND.The other §2.1 cases stay where the content is actually understood:
415): the bodyparser or the route decides400): already raised by the bodyparser's parse errors, e.g. invalid JSONBody parsing is handled in adonisjs/bodyparser#86, and the docs in adonisjs/v7-docs#89.
Tests
router.query()route definition with string controller and controller-tuple handlersurlFor.query()andsignedUrlFor.query()coverage in the existing method-specific builder testsnode:httpserver and dispatches afetch(url, { method: 'QUERY', body: ... })request through the routerQUERYrequests without aContent-Type, or with a malformed one ('',json,application/, ...), get a400and the handler is never calledapplication/sql) are acceptedE_INVALID_QUERY_CONTENT_TYPEQUERYto an unknown route still returns404npm run quick:test(675 tests),npm run typecheckand the compile step (tsdown+tsc --emitDeclarationOnly) all pass.npm run lintpasses on the changed files. A fulleslintrun currently reports 5 Prettier errors on lines this PR doesn't change. A clean9.xcheckout reports the same 5.🤖 Generated with Claude Code