MΓ³dulo 06 Β· DTOs, Validation & the Request Lifecycle β LecciΓ³n 3 de 3 Β· ~9 min
The request lifecycle
The order every request travels
The pipe didn't run by magic β it runs at a fixed point in Nest's request lifecycle. Every incoming request flows through the same ordered pipeline, and knowing the order is what lets you put logic in the right place:
- Middleware β runs first, before Nest even knows the route (raw
req/res; good for logging, CORS, body parsing). - Guards β answer one yes/no question: is this request allowed? (auth, roles). A
falsehere stops everything with a403. - Interceptors (pre) β wrap the handler; the code before
nextruns on the way in. - Pipes β transform and validate the handler's arguments. This is where your
ValidationPipelives. - The route handler β your controller method, finally running on clean, authorized input.
- Interceptors (post) β the code after
next, on the way out (reshape the response, log timing). - Exception filters β catch anything thrown at any stage and turn it into an HTTP response.
In an interview, say: "Guards decide if the request runs, pipes decide whether the input is valid β so authorization is settled before validation, and both before my handler sees anything."