Skip to main content

Route parameters

A route method receives a single RouteContext argument (unless you're using @Body, which injects the parsed DTO instead):

export interface RouteContext {
request: NextRequest;
params: Record<string, string>;
query: URLSearchParams;
json: (body: any, init?: ResponseInit) => NextResponse;
}
@Get("/:id")
getOne(context: RouteContext) {
const {id} = context.params;
const sort = context.query.get("sort");
return {id, sort};
}
FieldDescription
requestThe raw NextRequest — headers, cookies, request.json(), etc.
paramsCaptured :param path segments, as plain strings.
queryThe request's URLSearchParams.
json(body, init?)Shortcut for building a NextResponse.json() — used internally when a handler returns a plain value, and available for building custom-status responses yourself.