feat(router): add support for the QUERY HTTP method - #140
Open
DavideCarvalho wants to merge 1 commit into
Open
Conversation
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>
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 — the safe, idempotent method with a request body designed 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 builderrouter.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 just gives it the same ergonomic, type-safe surface as the other verbs.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 routernpm test(lint + 641 tests),npm run typecheckandnpm run buildall pass.🤖 Generated with Claude Code