Routing and request data
| Field | Description |
|---|---|
| ctx.params | Path parameter map (including "*" for wildcards) |
| ctx.query | Parsed query string values |
| ctx.headers | Request headers |
| ctx.method | Normalized HTTP method |
| ctx.path | Path without query string |
| ctx.url | Full request URL |
| ctx.request | Node.js IncomingMessage |
| ctx.response | Node.js ServerResponse |
Example
context.ts
app.get("/users/:id", (ctx) => {
return ctx.ok({
id: ctx.params.id,
page: ctx.query.page,
userAgent: ctx.headers["user-agent"],
path: ctx.path,
});
});Response helpers
- ctx.json(data, { status }) — JSON response
- ctx.text(body, { status }) — plain text
- ctx.ok(data) — JSON 200
- ctx.created(data) — JSON 201
- ctx.noContent() — 204
- ctx.readJson() — parse request body as JSON
Validated data
When using @orveth/validation-zod middleware, validated payloads are available on ctx.valid.body and ctx.valid.query.