Danet provides several parameter decorators to inject request-related data directly into your controller method arguments. These decorators allow you to access the request, response, headers, body, query parameters, URL parameters, session, and the full execution context.
Common decorators include:
@Req(): Injects the current request object.@Res(): Injects the current response object.@WebSocket(): Injects the current WebSocket instance.@Header(prop?: string): Injects all headers or a specific header by name.@Body(prop?: string): Injects the request body or a specific property from the body. If a DTO class is provided as the type hint for the parameter, Danet will automatically validate the body against it.@Query(param?: string, options?: QueryOption): Injects query parameters. You can specify a specific key or retrieve all query parameters. Use options.value to control how multiple values for the same key are handled ('first', 'last', or 'array').@Param(paramName: string): Injects a specific URL parameter (e.g., from /user/:userId).@Session(prop?: string): Injects the session object or a specific property from the session.@Context(): Injects the full ExecutionContext.
@Controller('/user')
class UserController {
@Get('/:userId')
async getUser(
@Param('userId') userId: string, // URL param
@Query('filter', { value: 'array' }) filter: string[], // Query param with array option
@Body() body: CreateUserDto, // Validated body
@Req() req: Request,
@Res() res: Response
) {
// ...
}
}