Hi everyone!
In this video I will introduce for you the request Lifecycle in NestJS application.
And in this video I will not write anything the code in this video, right?
Okay, after we watch this video you can feel free to test in this.
And what is the request life cycle.
And actually the term life cycle right here.
Exist in everywhere okay.
Anything in the world will have a life cycle.
Right.
And the NestJS is not exception.
We have a request lifecycle.
If you want to look up the document you can go to the FAQ right here and click on Request Life
Cycle.
Now let me explain for you.
Let me reminder for you in my previous video. I think in the first section, we already know
the life cycle.
When we have a request, it will accept us using the middleware first.
Right?
Middleware.
And after middleware, it will trigger the Guard
Right after Guard.
It will give the interceptor.
Right.
So this is the lifecycle of the request and response.
But what is, for example, in the guard we have a global guard.
We have a so many concept related to global guard okay or the interceptor.
It also have a global interceptor right.
And we have a something called controller level of the guard or the interceptor.
And we have a method level.
Okay.
And also we have a global.
So how it can be excuted.
For example with guard we have a global guard.
We have something called global controller.
Sorry the guard controller.
And we have a guard in the methods.
Now let me show you what it means inside the overview right here.
For example, if I go out into the interceptor now we will scroll down a little bit.
We have an interceptor right and right here.
It will use it into the class, it means this is a class level interceptor okay.
And we can actually do that in the methods.
Or we can use the global right here.
Now you can see this is a global interceptor.
And it is also available interceptor you can see and when we do the project, we will see this approach.
Don't worry about what it means right now.
You will understand later.
Okay.
And actually we can also use that in the in the method level right here.
Let me show you for example right here.
Let me open the the post controller here.
Okay.
Here will be the class level.
Class level.
And if I go in the @POST right here, it means this is the method level interceptor.
Okay.
And if we use something like this, I will call.
This will be the.
Something like this, I'll call
This will be the global interceptor.
And how it can be excuted.
Okay.
That's the concept of request lifecyle
Read more about that
If we scroll down a little bit right here, now, you can see, you can read a summary right here,
or you can read details.
You can read details for example like that, the middleware excute.
Uh, right here.
Right.
You can see, and after that we will go to the guard.
The guard will be start with global guard and then the controller guard.
And finally the route guard. This is a "route guard"
Or you can see the method level.
Now you can see, if we use something like this if we if we use something like 2 guards here and also
guard here.
What it's mean, the guard one will be executed first.
And after that it will run the guard 2
And after that we will go to the useGuard in method level
Okay, you can read more about them right here.
And interceptor is it will be the same. Let meread more about that.
When we have a incoming request it will accept by middleware okay.
And it will back to the global middleware and also the module middleware.
And the guard is similar.
Firstly we will the global guard and the second will be controller guard and route guard
Okay.
Interceptor will be the same right.
You can see it will be the same.
And also the pipes.
And we have so many things after each run, the some steps, it will come back to the controller
and service and post interceptor because the interceptor it will have a two way, right?
This is the interceptor.
And when we respond, it also have interceptor, right?
For that reason, it will trigger interceptor in this step.
And we also have exception.
And after that, the finally will be the response.
Right.
We can see the interceptor execute before the server response.
Right.
You can see okay, that's it. That's the concept of request life cycle.
You can read more about them in the topics right here.
But I think this very enough for you right now.
So that's it for the video.
I will see you in the next one.