Deleting Resources by ID

Learn how to delete resources in a NestJS application.

In any library, books might be lost, damaged, or deemed outdated. Just like in a physical library, where we might need to remove such books from the records, in our virtual library, we need a way to remove (or delete) a book from our system. In this section, we’ll equip our virtual library with the capability to remove books based on their unique identifier.

Updating BooksController

Removing a book from our virtual library deletes it from the collection. In HTTP methods, the DELETE method handles this action. It signals a resource’s removal. Just as taking a book off a shelf signifies its removal, the DELETE removes a resource from a database or application.

To create an endpoint for deleting a book by its id, follow these steps:

  1. Import the Delete decorator to specify this route HTTP verb.

Get hands-on with 1200+ tech skills courses.