API REFERENCE
Context
import { createContext } from '@rasenganjs/futon'; import type { Context, RuntimeContext, QueryParams, ServerInfo, } from '@rasenganjs/futon';
See Context Object and Query Parameters for usage and examples.
createContext()
function createContext( request: Request, params?: Record<string, string>, runtime?: RuntimeContext ): Context;
Factory that builds a fresh Context for a single request. Called internally by Futon.fetch() — you won't normally call this yourself outside of tests. query and response are both created lazily on first access and cached thereafter.
Context
interface Context< Body = any, Params = Record<string, string>, Query = QueryParams, > { request: Request; req: Request; // alias for `request` body: Body; // undefined until a body parser middleware sets it params: Params; // path params extracted by the Router query: Query & QueryParams; // lazily parsed, then cached runtime: RuntimeContext; response: ResponseBuilder; // lazily created, then cached res: ResponseBuilder; // alias for `response` state: Record<string, unknown>; set<T = unknown>(key: string, value: T): void; get<T = unknown>(key: string): T | undefined; }
RuntimeContext
interface RuntimeContext { env?: Record<string, string>; server?: ServerInfo; }
Carries platform-specific info so the same handler code runs unmodified on Node, Bun, Deno, and Cloudflare Workers. Accessible as ctx.runtime inside handlers/middleware.
ServerInfo
interface ServerInfo { preset: 'node' | 'bun' | 'express' | 'workerd' | 'wintercg' | 'unknown'; mode: 'development' | 'production'; port: number; host: string; rootDir: string; }
Set by the runtime adapter before serving. Accessible via ctx.runtime.server inside the request lifecycle, or app.serverInfo outside of it (e.g. in onInit).
QueryParams
interface QueryParams { (key: string): string | undefined; [key: string]: string | undefined; }
A callable-and-indexable object — ctx.query('page') and ctx.query.page both work. Parsed lazily from the URL on first access.
