https://docs.nestjs.com/controllers
Controllers
- 컨트롤러는 들어오는 요청을 처리하고 클라이언트에 응답을 반환하는 책임이 있다.
- 컨트롤러의 목적은 application 에 대한 특정 요청을 받는 것이다.
- [routing] 메커니즘은은 어떤 컨트롤러가 어떤 요청을 수신하는 지 제어한다.
- Frequently (자주), each controller has more than one route
- and different routes can perform different actions
- In order to create a basic controller, 우리는 [class]들과 [decorator]들을 사용합니다.
- 데코레이터는 class들을 요청된 메타데이터와 연관 짓고, 네스트가 라우팅맵을 생성할수 있도록 합니다.
- (tie requests to the corresponding controllers) (요청을 상응하는 컨트롤러에 묶는 것)
HINT
- For quickly creating a CRUD controller with the [validation] built-in, you may use the CLI's CRUD generator:
nest g resource [name]
Routing
- 예제에서는 basic controller 를 정의하는데 [@Controller()] 데코레이터를 사용하였다.
- We'll specify(지정하다) an optional route path prefix of [cats]
- Using a path prefix in a [@Controller()] decorator allows us to easily group a set of related routes,
- And minimize repetitve code.
- For example, we may choose to group a set of routes that manage interactions with a customer entity under the rout /customers.
- In that case, we could specify the path prefix [customers] in the [@Controllers()] decorator so that we don't have to repeat that portion of the path for each route in the file (@Contoller('cats') 라고 되어있다면, /cats 로 시작하는 모든 요청을 받는 다는 뜻인듯.