ResponseContext provides a mutable interface for customizing response properties before the final Response is constructed.
The API mirrors the Response object for familiarity, but allows mutation since the actual Response is built after the handler completes.
class UserHandler extends RouteHandler<Env, { id: string }> { async get(request: Request, env: Env, params?: { id: string }): Promise<any> { this.response.status = 201; this.response.headers.set('Set-Cookie', 'session=abc123'); return { userId: params.id }; }} Copy
class UserHandler extends RouteHandler<Env, { id: string }> { async get(request: Request, env: Env, params?: { id: string }): Promise<any> { this.response.status = 201; this.response.headers.set('Set-Cookie', 'session=abc123'); return { userId: params.id }; }}
HTTP status code for the response
200 Copy
200
HTTP status text for the response
'OK' Copy
'OK'
Headers to include in the response Works like Response.headers - use .set(), .append(), .delete(), etc.
Reset the context to default values
ResponseContext provides a mutable interface for customizing response properties before the final Response is constructed.
The API mirrors the Response object for familiarity, but allows mutation since the actual Response is built after the handler completes.
Example