Skip to content

FlareHttpContext

class FlareHttpContext

Full HTTP context passed to controllers, middleware, and handler functions.

Wraps the inbound FlareRequest (available as req) and exposes pipeline-scoped concerns: request state, parsed contract data via extract, and outbound cookie management via cookies.

Handed to you by the framework; see Requests.

req: FlareRequest
get cookies(): FlareCookies

returns FlareCookies

get state(): RequestState

returns RequestState

extract<T extends RequestDescriptor>(descriptor: T): TypedRequestContext<T>

Extracts the parsed and validated request inputs typed against a contract descriptor.

Pass a single method entry from a ContractToken and receive an object whose body, route, and query properties are fully typed according to what the descriptor declares. Fields not present in the descriptor resolve to never.

Zero-cost cast at runtime: no additional parsing is performed. Parsing and validation happen once in the pipeline before the handler runs.

descriptor T

returns TypedRequestContext<T>

Example:

const { body, route, query } = ctx.extract(UserContract.getUser);
sse(producer: (sse: SseWriter, signal: AbortSignal) => void | Promise<void>): FlareResponse

Opens a Server-Sent Events response and runs producer as the event source.

The response returns immediately with Content-Type: text/event-stream; the producer pushes frames through the SseWriter, which paces itself against the connection (one frame buffered). The stream ends when the producer settles or the request aborts; the producer’s signal is the request’s AbortSignal, so a long-lived loop can stop when the client leaves.

producer (sse: SseWriter, signal: AbortSignal) => void | Promise<void>

returns FlareResponse

Example:

return ctx.sse(async (sse, signal) => {
while (!signal.aborted) {
await sse.send({ event: "tick", data: { now: Date.now() } });
await delay(1000);
}
});

Learn: Requests

Last updated: