Skip to content

docs: add QUERY method docs#1447

Merged
pi0 merged 2 commits into
mainfrom
feat/query-cross-cutting-audit
Jul 9, 2026
Merged

docs: add QUERY method docs#1447
pi0 merged 2 commits into
mainfrom
feat/query-cross-cutting-audit

Conversation

@pi0x

@pi0x pi0x commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

PR 4 — Cross-cutting audits + docs from the HTTP QUERY method proposal (#1441). Completes the checklist now that core support (#1445) and the Accept-Query / requireContentType utils (#1446) have landed.

The audit finding is that no core logic change is needed — CORS and cache handling are already method-agnostic. This PR locks that behavior in with regression tests, documents the one real gotcha (CORS preflight), fixes a broken example, and adds an example doc page.

Audit results

Area Finding Action
CORS handleCors / isPreflightRequest never inspect the specific requested method; access-control-allow-methods just echoes methods. Default "*" already permits QUERY. Doc note + regression tests. QUERY is not CORS-safelisted, so explicit methods allowlists must include "QUERY".
Cache handleCacheHeaders has no method guard — keys off If-None-Match / If-Modified-Since regardless of method. QUERY already gets 304. Regression tests.
Proxy Already handled in #1445 (QUERY in PayloadMethods, forwarded with body).

Changes

  • src/utils/cors.ts — clarify the methods option jsdoc: include "QUERY" in explicit allowlists since browsers preflight it.
  • test/query.test.ts — matrix regression tests: QUERY preflight (wildcard + explicit allowlist) and 304 conditional caching (If-None-Match / If-Modified-Since).
  • examples/query.mjs — 🐛 bug fix: the example imported setAcceptQuery, but the util shipped as appendAcceptQuery (feat: add requireContentType and appendAcceptQuery utils #1446), so it failed to run. Corrected and verified end-to-end (QUERY200 + Content-Location, 415 on unsupported type, cacheable GET follow-up).
  • docs/1.guide/1.basics/2.routing.md — new "HTTP QUERY method" section covering app.query(), the read-with-a-body use case, body-size limits, and the CORS/cache/proxy parity notes.
  • docs/4.examples/handle-query.md — new example page walking through app.query(), appendAcceptQuery, requireContentType, and the cacheable-GET / Content-Location pattern; linked from the routing guide and the examples index.

Testing

  • pnpm vitest run test/query.test.ts → 38 passed (19 × web/node matrix)
  • pnpm vitest run test/unit/cors.test.ts test/utils.test.ts test/proxy.test.ts → all green
  • pnpm lint → clean
  • Manually ran node examples/query.mjs and exercised every path with curl

Closes the PR 4 checklist in #1441.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Added a new guide section for the HTTP QUERY method, including handler registration, reading request bodies, and enforcing body-size limits.
    • Documented QUERY caching behavior, proxy forwarding expectations, and CORS/preflight implications.
    • Expanded CORS docs to clarify that QUERY is not CORS-safelisted and must be explicitly included in allowed methods.
  • Examples
    • Added an “HTTP QUERY Method” example demonstrating correct header-based format negotiation and handler usage.
  • Tests
    • Added coverage for QUERY CORS preflight and conditional caching behavior.

Cross-cutting audits and docs for the HTTP QUERY method (RFC 10008),
completing the QUERY method support tracked in #1441.

- cors: document that `QUERY` is not CORS-safelisted, so explicit
  `methods` allowlists must include `"QUERY"` (no logic change — CORS
  is already method-agnostic).
- tests: regression coverage that a `QUERY` preflight works (wildcard
  and explicit allowlist) and that `handleCacheHeaders` returns `304`
  for `QUERY` on `If-None-Match` / `If-Modified-Since`.
- docs: add an HTTP `QUERY` method section to the routing guide
  covering `app.query()` and the read-with-a-body use case.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@pi0x
pi0x requested a review from pi0 as a code owner July 9, 2026 14:31
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Documentation, example code, and tests are updated for HTTP QUERY support. The routing guide and example pages describe QUERY usage and helpers, the runnable example switches to appendAcceptQuery, and tests cover CORS preflight and conditional cache behavior.

Changes

QUERY method docs, example, and tests

Layer / File(s) Summary
QUERY method documentation
docs/1.guide/1.basics/2.routing.md, docs/4.examples/handle-query.md, docs/4.examples/0.index.md
The routing guide and example docs add QUERY usage, helper references, and a link to the runnable example.
Accept-Query helper update
examples/query.mjs
The runnable QUERY example switches from setAcceptQuery to appendAcceptQuery for both discovery and QUERY responses.
Cors docs and QUERY tests
src/utils/cors.ts, test/query.test.ts
The CORS JSDoc clarifies QUERY allowlisting, and tests cover QUERY preflight plus conditional cache-header responses.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Suggested reviewers: pi0

Poem

Hop hop, I read the QUERY trail,
With bodies, caches, and headers to mail.
Preflight twirls by, then 304 sighs,
This bunny approves with bright round eyes.
🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: adding documentation for the QUERY method.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/query-cross-cutting-audit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pi0 pi0 changed the title feat: audit QUERY parity for CORS/cache + docs docs: add QUERY method docs Jul 9, 2026
- examples/query.mjs imported `setAcceptQuery`, but the util shipped as
  `appendAcceptQuery` (#1446) — the example failed to run. Verified the
  fixed example end-to-end (QUERY, 415, cacheable GET follow-up).
- docs: add an "HTTP QUERY Method" example page walking through
  `app.query()`, `appendAcceptQuery`, `requireContentType`, and the
  cacheable-GET / `Content-Location` pattern; link it from the routing
  guide and the examples index.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@pi0
pi0 merged commit 3eb3a57 into main Jul 9, 2026
9 checks passed
@pi0
pi0 deleted the feat/query-cross-cutting-audit branch July 9, 2026 14:43
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.

2 participants