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()

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…

Contents