[NestJs]네이밍,라우팅

코드깎는 노인·2021년 8월 4일
0
post-thumbnail

naming convention

  • 파일당 하나의 클래스만 생성한다
  • 클래스명에는 생성하는 내용과 관련되야 한다
  • 클래스명과 파일명은 항상 일치해야 한다
  • 파일명의 템플릿(name.type.ts)를 준수한다.

example

main.ts
 function bootstrap

app.controller.ts
 class AppController{}

app.module.ts
 class AppModule {

routing

import { Controller, Get } from "@nestjs/common";

@Controller('/app')
export class AppController {
  @Get('first')
  getHiRoute() {
    return "hi there";
  }
  @Get('second')
  getByeRoute() {
    return "bye there";
  }
}

@controller의 라우팅 파라미터는 높은단계의 라우팅을 담당하고 @get의 라우팅 파라미터는 컨트롤러의 서브라우팅이다.@get('first)는 localhost:3000/app/first로 라우팅 될것이다.

profile
내가 볼려고 만든 블로그

0개의 댓글