Skip to content

feat: parse the body of QUERY requests by default - #86

Open
DavideCarvalho wants to merge 1 commit into
adonisjs:11.xfrom
DavideCarvalho:feat/query-method
Open

DavideCarvalho wants to merge 1 commit into
adonisjs:11.xfrom
DavideCarvalho:feat/query-method

Conversation

@DavideCarvalho

Copy link
Copy Markdown

What

Adds QUERY to the default allowedMethods list returned by defineConfig, so request.body() is populated for QUERY requests the same way it is for POST, PUT, PATCH and DELETE.

allowedMethods: config.allowedMethods || ['POST', 'PUT', 'PATCH', 'DELETE', 'QUERY'],

Companion to adonisjs/http-server#140, which adds router.query().

Why

QUERY (RFC 10008) is a safe, idempotent method whose query is carried in the request content rather than the URL. Without this change the bodyparser skips QUERY requests and the route handler always sees an empty body.

Unsupported content types keep the current behavior (bodyType: 'unknown', raw stream left untouched), so routes can still handle custom query formats such as application/sql themselves.

Existing apps

Explicitly configured allowedMethods lists are not touched, and the starter kits set the list explicitly in config/bodyparser.ts, so existing and newly created apps need 'QUERY' added there to opt in:

  • adonisjs/starter-kits: api, api-monorepo/apps/backend, hypermedia, inertia-react, inertia-vue (config/bodyparser.ts)
  • adonisjs/v7-docs: content/guides/basics/body_parser.md and content/reference/config/bodyparser.md (covered in the docs PR for router.query())

Happy to send PRs for the starter kits too if you want them updated.

Tests

  • defineConfig({}) includes QUERY in allowedMethods
  • A JSON QUERY request populates request.body() with bodyType: 'json'
  • A urlencoded QUERY request populates request.body() with bodyType: 'urlencoded'
  • QUERY requests are skipped when allowedMethods is set explicitly without it

Supertest has no typed API for QUERY, so these tests send real requests with undici's fetch.

npm test (lint + 206 tests), npm run typecheck and the build (tsdown + tsc --emitDeclarationOnly) all pass.

🤖 Generated with Claude Code

The QUERY HTTP method (RFC 10008) carries the query in the request
content, so request.body() must be populated for it just like POST.
Add QUERY to the default allowedMethods list.

Refs adonisjs/http-server#140

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant