From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Controller fundamentals (@Post handler)

Controller fundamentals (@Post handler)

As we are moving towards learning how to create basic APIs with NestJS, in this lecture, we are going to learn about the post handler with Nest. So in the products controller, we are going to create a new method. Let's name it as add products. And as this method will handle the incoming post requests, we have to specify the post decorator above the method. Let me give at post that is the post decorator. So, now the add products method is marked with the post handler. In this method, we are going to define the functionality to store the products. Right now, as we are not using any database, we are just going to store the products in an array, though we will see how to deal with the database in later sections. Now instead of giving the functionality of inserting a new product here in the method, we are going to distribute the code and define the functionality in a separate file, because in that way we can make the code more manageable. I'm going to create a separate service file or we…

Contents