getRequestEvent
Returns the request event for the current server render, middleware chain, or server-function call.
Import
import { getRequestEvent } from "@solidjs/web";Type signature
function getRequestEvent(): RequestEvent | undefined;Examples
const event = getRequestEvent();const userId = event?.locals.userId;Learn more
Related types
RequestEvent
The per-request context available on the server: the incoming Request
and a locals bag integrations and middleware can hang state on (typed
through the augmentable RequestEventLocals). Frameworks typically
extend this shape with richer fields (e.g. a response head — see
ResponseStub).
interface RequestEvent { request: Request; locals: RequestEventLocals;}request
- Type:
Request
locals
- Type:
RequestEventLocals
RequestEventLocals
The type of RequestEvent.locals — a module-augmentable interface so
applications can type the state their middleware hangs on the event.
Augment it through the package that re-exports the event (interface
identity flows through the re-export chain):
declare module "@solidjs/web" { interface RequestEventLocals { user: User; }}The index signature keeps un-augmented usage permissive — locals is a
free-form bag by default — so augmentation adds precision for the keys
it names without gating existing code. The flip side: unaugmented keys
read as any rather than erroring, a deliberate trade (a strict-only
locals would break every untyped write that works today).
interface RequestEventLocals { [key: string | number | symbol]: any;}ResponseStub
See the server entry's ResponseStub — the shape of the mutable response
head integrations expose as event.response via module augmentation.
interface ResponseStub { status?: number; statusText?: string; headers: Headers; committed?: boolean;}status
- Type:
number
statusText
- Type:
string
headers
- Type:
Headers
committed
- Type:
boolean
Set by the integration once the response head has been derived/sent from this stub (status/headers can no longer change); consumers must treat later writes and cleanup-time retractions as no-ops.