Request Context

The context object available in all loaders and actions.

Properties

PropertyTypeDescription
ctx.request RO Request The raw Fetch API Request object
ctx.url RO URL Parsed URL with pathname, searchParams, etc.
ctx.params RO Record<string, string> Route parameters from dynamic segments
ctx.db RO Database Database interface for queries and mutations
ctx.auth RO AuthContext Authentication and authorization interface
ctx.sse RO SSEContext Server-Sent Events interface

Methods

ctx.formData
formData(): Promise<FormData>

Parse the request body as FormData for form submissions.

Returns: Promise<FormData> - Parsed form data
Example
const form = await ctx.formData();
const email = form.get('email');
const password = form.get('password');
ctx.json
json<T>(): Promise<T>

Parse the request body as JSON.

Returns: Promise<T> - Parsed JSON body
Example
const body = await ctx.json<{ name: string }>();
console.log(body.name);
ctx.redirect
redirect(url: string, status?: number): Response

Create a redirect response.

Parameters
NameTypeDescription
url string URL to redirect to
status optional number HTTP status code Default: 302
Returns: Response - Redirect response
Example
return ctx.redirect('/dashboard');
return ctx.redirect('/login', 303);
ctx.html
html(content: string, status?: number): Response

Create an HTML response.

Parameters
NameTypeDescription
content string HTML content
status optional number HTTP status code Default: 200
Returns: Response - HTML response
Example
return ctx.html('<h1>Hello World</h1>');