Skip to content

Delete

reference
1 min readUpdated

Kind: Constant

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

Part of: Common

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

Delete is a route handler decorator that maps an HTTP DELETE request to a controller method. Use it to define endpoints responsible for removing resources or performing delete-oriented actions at a specified path.

Definition

ts
createMappingDecorator(RequestMethod.DELETE)

Value

ts
createMappingDecorator(RequestMethod.DELETE)

Diagram

mermaid
graph LR
  Client[HTTP Client] -->|DELETE /users/:id| Router[HTTP Router]
  Router -->|matches route| Controller[Controller Method]
  Controller -->|@Delete(':id')| Handler[Delete Handler]
  Handler --> Response[HTTP Response]

Usage

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

@Controller('users')
export class UsersController {
  @Delete(':id')
  async remove(@Param('id') id: string) {
    await this.usersService.remove(id);

    return {
      message: `User ${id} deleted successfully`,
    };
  }
}

AI Coding Instructions

  • Apply @Delete() only to controller methods that handle HTTP DELETE requests.
  • Provide a route path such as ':id' when the handler deletes a specific resource.
  • Use parameter decorators like @Param() to access path values required by the delete operation.
  • Delegate deletion logic to a service layer rather than placing persistence logic directly in the controller.
  • Return an appropriate response or configure the expected HTTP status code for successful deletion.

Used by

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

Imported by (7)

  • 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
  • UsersControllersample/05-sql-typeorm/src/users/users.controller.ts:14
  • CatsControllersample/06-mongoose/src/cats/cats.controller.ts:7
  • UsersControllersample/07-sequelize/src/users/users.controller.ts:6

Was this page helpful?

Download as PDF
Delete — NestJS head-to-head