Skip to content

Get

reference
1 min readUpdated

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

ts
createMappingDecorator(RequestMethod.GET)

Value

ts
createMappingDecorator(RequestMethod.GET)

Diagram

mermaid
graph 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

ts
import { 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 HTTP GET requests.
  • 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 GET handlers 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)

  • AppControllerintegration/cors/src/app.controller.ts:3
  • ErrorsControllerintegration/hello-world/src/errors/errors.controller.ts:3
  • HelloControllerintegration/hello-world/src/hello/hello.controller.ts:6
  • HostControllerintegration/hello-world/src/host/host.controller.ts:6
  • HostArrayControllerintegration/hello-world/src/host-array/host-array.controller.ts:6
  • AppV1Controllerintegration/inspector/src/app-v1.controller.ts:3
  • AppV2Controllerintegration/inspector/src/app-v2.controller.ts:3
  • CatsControllerintegration/inspector/src/cats/cats.controller.ts:8

…and 69 more.

Was this page helpful?

Download as PDF
Get — NestJS head-to-head