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
tscreateMappingDecorator(RequestMethod.SEARCH)
Value
tscreateMappingDecorator(RequestMethod.SEARCH)
Diagram
mermaidgraph 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
tsimport { 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 HTTPSEARCHrequests. - 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
SEARCHHTTP 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()forGETorPOSTbehavior.
Was this page helpful?