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.
Assignment: Modifying request headers - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Assignment: Modifying request headers
Let's implement one more assignment where we modify the request headers with the help of interceptors. Consider a scenario where the NestJS app interacts with an external API that requires JSON formatted requests only. So we are going to convert the outgoing request to the JSON format using the interceptor. We already have the interceptor file ready, I will create a constant named request and assign the context dot switch to HTTP dot get request. With this, we would be able to access the request object. In the next step, we will specify the content type headers to ensure the request is in JSON format. To do this, we will set the content type header of the request to application slash JSON. So with this line of code, request headers are modified, and the content type is set to application slash JSON for all the outgoing requests. This tells the server that the data being sent is in JSON format. Let's also log the headers. I'll give console log and display the headers. Now 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 interceptors3m
-
(Locked)
Understanding interceptor5m 54s
-
(Locked)
Assignment: Transforming response data4m 42s
-
(Locked)
Assignment: Modifying request headers3m 49s
-
(Locked)
Assignment: Hiding sensitive information5m 50s
-
(Locked)
Exception mapping3m 23s
-
(Locked)
Data validation with interceptor5m 37s
-
(Locked)
Authentication and authorization4m 24s
-
(Locked)
Applying global interceptors2m 39s
-
(Locked)
-
-
-
-
-
-