Follow along notes from Michael Guay on Youtube
Source: https://www.youtube.com/watch?v=x1W3FJ1RJlM
All credits to Michael Guay for the lesson.
What I learned is that the path a request goes through in order is...
- Middleware - For things like authenticating a user
- Guards - To check a user is authenticated before getting to the controller (manager of the task) among other use cases
- Interceptor (before) - Can be used to log the method, url, userAgent, ip, controller name (ie., AppController), controller handler/method name (ie., getHello). Can also be used to transform incoming data
- Pipes - Can be used to freeze parameters in the request so it isn't mistakenly changed in the code. Also validate input data, transform input data, etc. Typical usage is validating request parameters with built in NestJS pipes like ParseIntPipe, ParseArrayPipe, ParseUUIDPipe
- Route handler - The "manager" that tells the provider (ie., service/worker/task implementer) what to do
- Interceptor (after) - Can get the response and status code after handled by the control handler (ie., the method/function inside the manager). Useful for logging. Can be accessed via
next.handle().pipe(tap(res=>{}))
- Exception filters - To log errors internally or change the error response into user friendly wording for better UI Then it becomes a beautiful response
Diagram by Demisx:
Source