03 / 04

How do you extract route params, query params, and request body in a NestJS controller?

Use @Param('id') for route parameters, @Query('page') for query strings, @Body() for the request body, and @Headers('authorization') for headers. @Req() and @Res() give access to the raw Express/Fastify objects but should be avoided when possible as they couple code to the underlying platform.

Extracting request data
Available parameter decorators:
  1. 1

    @Param('key') — extracts a named route parameter.

  2. 2

    @Query('key') — extracts a named query string parameter.

  3. 3

    @Body() — extracts the full request body (or @Body('key') for a specific field).

  4. 4

    @Headers('key') — extracts a specific request header.

  5. 5

    @Req() — raw request object (Express/Fastify); avoid when possible.

  6. 6

    @Res() — raw response object; switches to library-specific mode (use passthrough: true to avoid side effects).