Skip to content

Requests

FlareRequest and FlareHttpContext - fields, body readers, params, cookies, and the request pipeline surface.

AI generated, pending review Updated 10 days ago · Flare 0.3

Every handler and middleware hook receives a FlareHttpContext (ctx in inline routes, this.ctx on controllers). The inbound message is ctx.req, a FlareRequest.

For route matching see Routing behavior. For handler return values see Requests and responses. For contract validation see HTTP contracts.

A read-mostly wrapper around what arrived on the wire.

FieldTypeMeaning
methodstringHTTP verb as received
urlstringFull request URL string
pathstringPath without query string
headersHeadersRequest headers
rawRouteParamsRecord<string, string>Decoded :segment / *rest values
rawQueryParamsURLSearchParamsParsed query string
requestIdstringFramework-assigned id (X-Request-Id when enabled)
rawBodyArrayBuffer | nullBytes after buffer() / text() / json()
signalAbortSignalClient disconnect signal
startTimenumber | undefinedPresent when request timing is enabled
nativeRequestunknownAdapter-specific raw request
MethodReturnsBehavior
buffer(maxBytes?)Promise<ArrayBuffer | null>Full body in memory
text()Promise<string | null>UTF-8 text
json()Promise<JsonValue>Parsed JSON; null for an empty body; rejects invalid JSON
stream()AsyncIterable<Uint8Array>Chunked read without buffering

Pick one strategy per request. After buffer() / text() / json() starts, stream() throws.

Over-limit bodies throw ContentTooLarge, mapped to 413.

MemberPurpose
ctx.reqThe inbound FlareRequest
ctx.extract(descriptor)Parsed contract values for controllers
ctx.cookiesRead and set cookies (including signed)
ctx.statePer-request state tokens
ctx.sse(producer)Open a Server-Sent Events response

Without a contract, read the wire form:

host.http.get("/users/:id", (ctx) => {
const id = ctx.req.rawRouteParams["id"];
const include = ctx.req.rawQueryParams.get("include");
return { id, include };
});

With descriptor fields on the route options, read parsed values from scope.input in the handler. Invalid shapes short-circuit with 400 before middleware (route/query) or before the handler (body).

  • No body in descriptor: use ctx.req body readers manually.
  • JSON body schema: read scope.input.body (inline) or ctx.extract(entry).body (controller).
  • body: stream: iterate ctx.req.stream() or scope.input.body (same iterable).