Skip to content

Request

reference
1 min readUpdated

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.

Example: logout(@Request() req)

Request is a route-handler parameter decorator that injects the underlying platform request object into a controller method parameter. Use it when a handler needs access to request metadata, headers, body data, cookies, or platform-specific request APIs.

Definition

ts
() => ParameterDecorator

Value

ts
createRouteParamDecorator(
  RouteParamtypes.REQUEST,
)

Diagram

mermaid
graph LR
  Client[HTTP Client] --> Router[Route Router]
  Router --> Handler[Controller Handler]
  RequestDecorator["@Request()"] --> Handler
  PlatformRequest[Underlying Request Object] --> RequestDecorator
  RequestDecorator --> Parameter[Decorated req Parameter]

Usage

ts
import { Controller, Get, Request } from '@nestjs/common';

@Controller('account')
export class AccountController {
  @Get('logout')
  logout(@Request() req: any) {
    const authorization = req.headers.authorization;

    return {
      message: 'Logout request received',
      authorization,
    };
  }
}

AI Coding Instructions

  • Use @Request() only on route handler parameters where direct access to the platform request object is required.
  • Prefer dedicated decorators such as @Body(), @Param(), @Query(), or @Headers() when only a specific request value is needed.
  • Keep request-object usage platform-aware; its exact shape may differ between Express, Fastify, or other HTTP adapters.
  • Type the injected request parameter with the appropriate platform request type instead of using any when adapter-specific APIs are used.

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (1)

  • AuthControllersample/19-auth-jwt/src/auth/auth.controller.ts:13

Was this page helpful?

Download as PDF
Request — NestJS head-to-head