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.
Accessing arguments with getArgs() - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Accessing arguments with getArgs()
Previously, we saw the getArgumentsByIndex method, which takes an index value and returns the arguments based on that. There is one more method which returns the request and response arguments, but in a more simplified and straightforward manner. It is the getArguments method. This method returns an array containing all the arguments passed to the execution context. So here in the code, let me give const. I am going to destructure the request and response parameters in an array and assign the context.getArgs method. If I hover on this method, it says that it returns the array of arguments being passed to the handler. So now we can directly access the request and response parameters and their properties. Let's test it out. I'll open the controller file and we'll add a query decorator as well in the get handlers method that is, and I will return the query value as well. In the guard file, I'll give a console statement that logs the request dot query. I'll go to the postman and in the…
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)
Introduction to guards4m 14s
-
(Locked)
Understanding guard5m 33s
-
(Locked)
Understanding ExecutionContext6m 50s
-
(Locked)
Accessing arguments with getArgs()3m 42s
-
(Locked)
Limiting controller access with guard4m 6s
-
(Locked)
Understanding switchToHttp() method4m 59s
-
(Locked)
Assignment: API key authorization6m 10s
-
(Locked)
Applying multiple guards3m 14s
-
(Locked)
Defining custom metadata5m 6s
-
(Locked)
Setting custom metadata: A better way3m 25s
-
(Locked)
Applying role for specific handlers10m 3s
-
(Locked)
Applying multiple roles1m 35s
-
(Locked)
Applying global guards4m 46s
-
(Locked)
-
-
-
-
-
-
-