Kind: Constant
Source: packages/common/decorators/http/request-mapping.decorator.ts
Part of: Common
Route handler (method) Decorator. Routes HTTP GET requests to the specified path.
Get is a route handler decorator that maps an HTTP GET request to a controller method. Use it to expose read-oriented endpoints, optionally providing a path that is combined with the controller's base route.
Definition
tscreateMappingDecorator(RequestMethod.GET)
Value
tscreateMappingDecorator(RequestMethod.GET)
Diagram
mermaidgraph LR Client[HTTP Client] -->|GET /users/:id| Controller[Controller Base Path: /users] Controller --> Get["@Get(':id')"] Get --> Handler[Controller Method] Handler --> Response[HTTP Response]
Usage
tsimport { Controller, Get, Param } from '@nestjs/common';
@Controller('users')
export class UsersController {
@Get(':id')
findOne(@Param('id') id: string) {
return {
id,
name: 'Ada Lovelace',
};
}
@Get()
findAll() {
return [];
}
}
AI Coding Instructions
- Apply
@Get()only to controller methods that handle HTTPGETrequests. - Provide a relative route path such as
':id'or'search'; it is combined with the enclosing@Controller()path. - Use parameter decorators such as
@Param(),@Query(), and@Headers()to access request data instead of manually parsing the request where possible. - Keep
GEThandlers read-oriented and avoid side effects; use@Post(),@Patch(), or@Delete()for state-changing operations.
Used by
77 references from 77 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.
Imported by (77)
AppController—integration/cors/src/app.controller.ts:3ErrorsController—integration/hello-world/src/errors/errors.controller.ts:3HelloController—integration/hello-world/src/hello/hello.controller.ts:6HostController—integration/hello-world/src/host/host.controller.ts:6HostArrayController—integration/hello-world/src/host-array/host-array.controller.ts:6AppV1Controller—integration/inspector/src/app-v1.controller.ts:3AppV2Controller—integration/inspector/src/app-v2.controller.ts:3CatsController—integration/inspector/src/cats/cats.controller.ts:8
…and 69 more.
Was this page helpful?