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.
Fetching queries - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Fetching queries
In NestJS, the query decorator is used to extract query parameters from the incoming HTTP request. It is commonly used with the GET decorator to handle GET requests and retrieve data based on query parameters. It works just like the param decorator, but instead of fetching the URL params, it fetches the URL query parameters. Query parameters are typically appended to the URL after a question mark and separated by an ampersand sign. For example, if we have a URL like this, the name and ID are considered as query parameters. Also giving the name and ID inside the query decorators argument would extract its given values. Let's try a practical example. Inside the controller file, I'll give the get handler and give the method as fetch query. Then I'll give the query decorator inside the method with the argument as name, which we want to fetch. the property in which we want to fetch the query parameter value. Then I'll simply return a string message, which displays the query parameter value…
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)
-
-
-
-
-
-
-
-
-
-