처음부터 차근차근

[NestJS] Request Lifecycle 본문

FrameWork/NestJS

[NestJS] Request Lifecycle

HangJu_95 2023. 11. 25. 12:04
728x90

NestJS Request Lifecycle

이번 글에서는 NestJS Application에서 어떠한 Request가 오고 나서 Response의 생명주기를 다룹니다.

NestJS는 Node.js의 Express가 해결해주지 못했던 아키텍쳐에 대한 고민을 해결하기 위해 VueJS, AngularJS 등을 참고하여 만든 백엔드 프레임워크입니다.

그렇기 때문에 NestJS에는 클라이언트의 요청을 처리하기 위해 프레임워크가 제공하는 일련의 생명주기가 존재합니다.

NestJS Request 생명주기 https://dkrnfls.tistory.com/83

 위 그림을 예시로 봤을때 큰 틀에서 보면

Middleware -> Guard -> Interceptor -> Pipe -> Controller -> Interceptor

이러한 순서대로 처리됩니다.

그리고 각 단계에서 global, controller, route로 세분화 해서 나누어지는 것을 확인할 수 있습니다.

또한 예외 상황(에러 발생)이 발생할 시에는 @useCatch로 Exception filter에서 처리가 가능합니다.

 

NestJS 공식 문서 Request lifecycle

더보기
  1. Incoming request
  2. Middleware
    • 2.1. Globally bound middleware
    • 2.2. Module bound middleware
  3. Guards
    • 3.1 Global guards
    • 3.2 Controller guards
    • 3.3 Route guards
  4. Interceptors (pre-controller)
    • 4.1 Global interceptors
    • 4.2 Controller interceptors
    • 4.3 Route interceptors
  5. Pipes
    • 5.1 Global pipes
    • 5.2 Controller pipes
    • 5.3 Route pipes
    • 5.4 Route parameter pipes
  6. Controller (method handler)
  7. Service (if exists)
  8. Interceptors (post-request)
    • 8.1 Route interceptor
    • 8.2 Controller interceptor
    • 8.3 Global interceptor
  9. Exception filters
    • 9.1 route
    • 9.2 controller
    • 9.3 global
  10. Server response

 

'FrameWork > NestJS' 카테고리의 다른 글

[NestJS] Guard  (0) 2023.11.27
[NestJS] Middleware  (0) 2023.11.25
[NestJS] Module  (1) 2023.11.24
[NestJS] Providers  (0) 2023.11.24
[NestJS] Controller  (1) 2023.11.24