Kind: Constant
Source: packages/common/decorators/http/route-params.decorator.ts
Part of: Common
Route handler parameter decorator. Extracts the Request
object from the underlying platform and populates the decorated
parameter with the value of Request.
Alias for
Req is a route handler parameter decorator that injects the underlying platform request object into a controller method parameter. It is typically used when access to raw request details—such as headers, cookies, URL parameters, or platform-specific properties—is needed.
Definition
tsRequest
Value
tsRequest
Diagram
mermaidgraph LR A[Incoming HTTP Request] --> B[Platform Adapter] B --> C[Controller Route Handler] C --> D[@Req() Decorated Parameter] D --> E[Request Object]
Usage
tsimport { Controller, Get, Req } from '@nestjs/common';
import type { Request } from 'express';
@Controller('users')
export class UsersController {
@Get('profile')
getProfile(@Req() request: Request) {
return {
userAgent: request.headers['user-agent'],
path: request.path,
};
}
}
AI Coding Instructions
- Use
@Req()only when the full underlying request object is required; prefer focused decorators such as@Body(),@Param(), or@Headers()for specific values. - Type the parameter using the request type provided by the active HTTP platform, such as Express
Requestor FastifyFastifyRequest. - Avoid coupling business logic directly to the raw request object; extract required values in the controller and pass them to services.
- Remember that request properties may vary between HTTP adapters, so avoid relying on adapter-specific fields unless the application is intentionally platform-specific.
Used by
6 references from 6 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.
Imported by (6)
AppController—integration/nest-application/app-locals/src/app.controller.ts:4AppController—integration/nest-application/global-prefix/src/app.controller.ts:3ExpressController—integration/nest-application/raw-body/src/express.controller.ts:4FastifyController—integration/nest-application/raw-body/src/fastify.controller.ts:4PassthroughInterceptor—integration/nest-application/sse/src/app.controller.ts:28AppController—integration/nest-application/use-body-parser/src/app.controller.ts:4
Was this page helpful?