Class 02: Routing, Controller và Dependency Injection
Tổng quan bài học
Controller và Route trong NestJS
Controller là gì?
Cú pháp khai báo Controller
import { Controller, Get } from '@nestjs/common';
@Controller('hello') // Prefix route: /hello
export class HelloController {
@Get() // Route: GET /hello
getHello(): string {
return 'Xin chào từ NestJS!';
}
}Các decorator xử lý route:
Decorator
HTTP Method
Mô tả
Ví dụ đầy đủ:
DTO (Data Transfer Object)
Giới thiệu Dependency Injection
Tạo Service
Sử dụng Service trong Controller
Bài tập thực hành
Mục tiêu
Yêu cầu
Gợi ý mở rộng
Last updated