Getting Resources by ID
Learn how to create resources in a NestJS application.
We'll cover the following
The ability to retrieve individual books by their unique identifier adds a crucial layer of specificity to our virtual library. This section will implement this functionality in our books-api
, allowing users to pinpoint the book they seek using its unique identifier within our virtual library.
Updating BooksController
Our application will have a route to fetch a book by its unique identifier. Following the RESTful and HTTP standards, we’ll create the endpoint /books/:id
using the GET
HTTP method. This method helps retrieve data without modifying it, making it the perfect choice for our needs.
Let’s create our route by following these steps:
Import the
Get
decorator to specify the HTTP verb and route for this endpoint:
Get hands-on with 1400+ tech skills courses.