Skip to content

Patch

reference
1 min readUpdated

Kind: Constant

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

Part of: Common

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

Patch is a method decorator that maps an HTTP PATCH request to a controller handler. It is used to define endpoints for partial resource updates and delegates route metadata creation to the shared request-mapping decorator infrastructure.

Definition

ts
createMappingDecorator(RequestMethod.PATCH)

Value

ts
createMappingDecorator(RequestMethod.PATCH)

Diagram

mermaid
graph LR
  Client[HTTP Client] -->|PATCH /resource/:id| Router[Nest Router]
  Router --> Controller[Controller Method]
  Patch["@Patch(path) decorator"] -->|Registers PATCH route metadata| Controller
  Controller --> Handler[Update Resource Logic]

Usage

ts
import { Body, Controller, Param, Patch } from '@nestjs/common';

@Controller('users')
export class UsersController {
  @Patch(':id')
  updateUser(
    @Param('id') id: string,
    @Body() updateUserDto: { displayName?: string },
  ) {
    return {
      id,
      ...updateUserDto,
    };
  }
}

AI Coding Instructions

  • Apply @Patch() only to controller methods that handle partial updates of an existing resource.
  • Provide a path such as ':id' when the handler needs to identify a specific resource.
  • Use DTOs with optional fields for PATCH request bodies rather than requiring a complete resource payload.
  • Combine @Patch() with parameter decorators such as @Param(), @Body(), and validation pipes as needed.
  • Avoid using @Patch() for full replacement semantics; prefer @Put() when clients must send the complete resource representation.

Used by

4 references from 4 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (4)

  • DatabaseControllerintegration/inspector/src/database/database.controller.ts:14
  • DogsControllerintegration/inspector/src/dogs/dogs.controller.ts:14
  • UsersControllerintegration/inspector/src/users/users.controller.ts:14
  • UsersControllerintegration/repl/src/users/users.controller.ts:14

Was this page helpful?

Download as PDF
Patch — NestJS head-to-head