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 (fetching params) - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Controller fundamentals (fetching params)
So far, we have seen how to get the products and add the products. Now let's see how to get a single product data by passing the params. Inside the controllers file, I'll define a new get handler with the method, let's say get product. Now the issue is that we have two get decorators in the same controller, and none of them has a unique route path given. So in this situation, nest will consider the first get decorator only and will ignore the second one. So the second decorator will never be executed. But good thing for us, we actually want to get a single product based on its ID. So here in the get, I will set the route path to id. That means the route will be slash products slash id. But remember that we want to pass the actual id in the route params and based on the id we get the product data. So that means the id parameter should be dynamic. And if you have worked with the ExpressJS, there we can set the dynamic segments of route params by giving a colon sign, we will do the same…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Understanding controllers5m 10s
-
(Locked)
Controller fundamentals (@Get handler)4m 21s
-
(Locked)
Controller fundamentals (Headers)3m 35s
-
(Locked)
Controller fundamentals (@Post handler)8m 57s
-
(Locked)
Controller fundamentals (@Post handler), part 2 with modules6m 56s
-
(Locked)
Controller fundamentals (fetching params)6m 44s
-
(Locked)
Controller fundamentals (@Put handler)10m 18s
-
(Locked)
Controller fundamentals (@Patch handler)4m 8s
-
(Locked)
Controller fundamentals (@Delete handler)3m 24s
-
(Locked)
Request object4m 42s
-
(Locked)
Response object2m 6s
-
(Locked)
Fetching queries3m 24s
-
(Locked)
@HttpCode vs. @Res decorator3m 22s
-
(Locked)
HTTP response status2m 53s
-
(Locked)
-
-
-
-
-
-
-
-
-
-