@Query()

Extracts query-string parameters from the request into a handler parameter.

Since NestJS 10/11 Spec ↗

Syntax

@Query(propertyOrPipe?, ...pipes)

Parameters

NameTypeRequiredDescription
property string No Optional name of a single query parameter to extract.
pipes PipeTransform[] No Optional pipes applied to the extracted value.

Returns

ParameterDecorator — A decorator that binds query params to the parameter.

Examples

import { Controller, Get, Query, DefaultValuePipe, ParseIntPipe } from '@nestjs/common';

@Controller('cats')
export class CatsController {
  @Get()
  find(
    @Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,
    @Query('search') search?: string,
  ) {
    return { page, search };
  }
}

Notes

Query values arrive as strings. Use DefaultValuePipe and ParseIntPipe to supply defaults and coerce types, or bind a validated DTO with @Query() and the ValidationPipe in transform mode.