728x90
반응형
Nest.Js는 데코레이터를 효율적으로 활용한다. @로 시작하는 데코레이터를 선언하여 사용한다.
기본 메소드 데코레이터 : @Get, @Post, @Delete, @Patch ..
변수 데코레이터 : @Body, @Parameter ..
기본 데코레이터 활용 예시
import { Controller, Get, Param, Post, Delete, Patch, Body, Query } from '@nestjs/common';
@Controller('movies')
export class MoviesController {
@Get()
getAll() {
return 'This will return all movies';
}
@Get('/search')
search(@Query('year') searchingYear: string) {
return `We are searching for a movie made after: ${searchingYear}`;
}
@Get('/:id')
getOne(@Param('id') movieId: string) {
return `This will return one movie with the id : ${movieId}`;
}
@Post()
create(@Body() movieData) {
console.log('movieData: ', movieData);
return movieData;
}
@Delete('/:id')
remove(@Param('id') movieId: string) {
return `This will delete a movie with the id : ${movieId}`;
}
@Patch('/:id')
patch(@Param('id') movieId: string, @Body() updateData) {
return {
updatedMode: movieId,
...updateData,
};
}
}
728x90
반응형
'IT > Nest.js' 카테고리의 다른 글
nest : 이 시스템에서 스크립트를 실행할 수 없으므로.. (0) | 2023.02.16 |
---|---|
Nest.js 프로젝트 특징 (0) | 2022.12.21 |
Nest.js 프로젝트 설정 (0) | 2022.11.13 |