controller
https://docs.nestjs.com/controllers

cats.controller.ts created with CLI '$ nest g controller cats'
Response#
- 표준
- JS 객체 - (직렬화) → JSON
- 원시값 → 값
- 상태 코드
- post (201)
- else (200)
- 커스텀
- 라이브러리
findAll(@Res() response)response.status(200).send()
클라이언트 요청 객체 (@Res() response)#
@Request(), @Req() | req |
@Response(), @Res()* | res |
@Next() | next |
@Session() | req.session |
@Param(key?: string) | req.params / req.params[key] |
@Body(key?: string) | req.body / req.body[key] |
@Query(key?: string) | req.query / req.query[key] |
@Headers(name?: string) | req.headers / req.headers[name] |
@Ip() | req.ip |
@HostParam() | req.hosts |
표준 HTTP 데코레이터#
@Get,@Post,@Put,@Delete,@Patch,@Options,@Head@Allendpoint that handles all of them.
라우트 와일드 카드#
@Get("ab*d") → 정규식
상태코드#
헤더#
@Header('Cache-Control, 'none')`
리디렉션#
@Redirect('https://nestjs.com', 301)@Redirect('https://nestjs.com')- override
Route parameters#
하위 도메인 라우팅#
호스트 매개변수 토큰
Scope#
요청 간의 거의 모든 것이 공유된다. (다중 스레드가 아님)
- DB Connection Pool, 전역 상태 싱글톤 서비스
- GraphQL 의 요청별 캐싱 등 제어 가능한 항목이 있다.
비동기성#
- Promise 의 결과 값을 받는 방법
페이로드 요청#
CreateCatDto 는 클래스로 작성한다.
- 클래스는 ES6의 표준 → 컴파일된 JS 에서 실제 Entity 로 보존된다.
- cf. ts 인터페이스는 컴파일된 JS 에서 제거되어, NestJS 가 런타임에 참조할 수 없음.
- 컴파일된 JS 에서 실제 Entity 로 보존된다는 것의 의미
- NestJS 가 런타임에 참조한다는 것의 의미
Controller 를 NestJS 가 알게 하기 app.module.ts#
응답 객체, 라이브러리 종속성#
@Res → express 에 종속
- 테스트 작성시 express 의존 필요
- Nest 표준 응답 처리 위반 - Interceptor, Decorators 호환 문제
@Res({ passthrough: true })설정으로 해결가능