OOrveth

Documentation

Context

RequestContext fields and response helpers in Phase 1.

Routing and request data

FieldDescription
ctx.paramsPath parameter map (including "*" for wildcards)
ctx.queryParsed query string values
ctx.headersRequest headers
ctx.methodNormalized HTTP method
ctx.pathPath without query string
ctx.urlFull request URL
ctx.requestNode.js IncomingMessage
ctx.responseNode.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.