Skip to content

Search

reference
1 min readUpdated

Kind: Constant

Source: packages/common/decorators/http/request-mapping.decorator.ts

Part of: Common

Route handler (method) Decorator. Routes HTTP SEARCH requests to the specified path.

Search is a route-handler method decorator that maps an HTTP SEARCH request to a controller method. Use it to declare WebDAV-style or custom SEARCH endpoints and optionally associate the handler with a specific route path.

The decorator integrates with the framework’s request-mapping metadata so the router can discover the method and dispatch matching SEARCH requests to it.

Definition

ts
createMappingDecorator(RequestMethod.SEARCH)

Value

ts
createMappingDecorator(RequestMethod.SEARCH)

Diagram

mermaid
graph LR
  Client[HTTP Client] -->|SEARCH /resources| Router[HTTP Router]
  Router -->|Matches route metadata| Controller[Controller Method]
  SearchDecorator["@Search('/resources')"] -->|Registers SEARCH mapping metadata| Controller
  Controller --> Response[HTTP Response]

Usage

ts
import { Controller } from '@nestjs/common';
import { Search } from '@nestjs/common/decorators/http/request-mapping.decorator';

@Controller('documents')
export class DocumentsController {
  @Search()
  searchDocuments() {
    return {
      results: [],
    };
  }

  @Search('advanced')
  advancedSearch() {
    return {
      results: [],
      filtersApplied: true,
    };
  }
}

AI Coding Instructions

  • Apply @Search() only to controller methods that should handle HTTP SEARCH requests.
  • Pass a path argument such as @Search('advanced') when the handler should map to a sub-route; omit it to use the controller-level path.
  • Ensure the deployment server, proxy, and HTTP client support the non-standard SEARCH HTTP method.
  • Keep search-specific request parsing and validation in the handler or dedicated DTO/validation layer rather than in the decorator.
  • Use the framework’s other request-mapping decorators for standard HTTP verbs instead of overloading @Search() for GET or POST behavior.

Was this page helpful?

Download as PDF
Search — NestJS head-to-head