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.

Request object

Request object

In NestJS, there are multiple ways where we can access different parts of an HTTP request. Until now we have seen and used the body decorator. Now the body decorator is used to extract the request body from an incoming HTTP request. Typically, it is used in conjunction with DTO, that is, data transfer objects, to automatically map the incoming request body to a class instance. The body decorator simplifies the process of extracting data from the request body and validating it. Commonly used to extract JSON or form data from the request body. What if we want to access the entire request object rather than the request body only? In that case, Nest provides two decorators, which are request and response decorators. The REQ, that is request decorator, provides direct access to the express request object. by allowing us to access various properties and methods of the incoming HTTP request, such as headers, body, query parameters, etc. It provides more low-level control over the request…

Contents