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.

Understanding interceptor

Understanding interceptor

Now, let's see how to implement the interceptor and understand the code syntax. To create a new interceptor, I will give the nest CLI command, nest generate ITC, which is short for interceptor. You can also give the whole word that is interceptor. Then I'll give slash interceptors, which is going to be the name of the folder and slash test, which is the interceptor name, hyphen hyphen, no spec. And the file is created. Let me open it. And we get the default boilerplate code for the interceptor. And as you can see, there are a bunch of interfaces imported which are used by the interceptor. So let's break down the syntax and understand it. Starting with the import statements, first we have the call handler interface. This interface represents a handler, a handler that processes the request and produces a response. Then we have the execution context interface, which we already saw in the guards section. So to get the details about the request and response objects in the interceptor, we…

Contents