Structured APIs
NestJS (Node) and FastAPI (Python) are frameworks for robust APIs.
NestJS (TypeScript)
npm i -g @nestjs/cli
nest new my-api
cd my-api
npm run start:dev
NestJS Structure
src/
├── app.module.ts
├── users/
│ ├── users.controller.ts # Endpoints
│ ├── users.service.ts # Logic
│ ├── users.module.ts # Registration
│ └── dto/ # Validation
Controller
@Controller('users')
export class UsersController {
constructor(private usersService: UsersService) {}
@Get()
findAll() {
return this.usersService.findAll()
}
@Post()
create(@Body() createUserDto: CreateUserDto) {
return this.usersService.create(createUserDto)
}
}
FastAPI (Python)
We saw it in the Cook level. Comparison:
| Aspect | NestJS | FastAPI |
|---|---|---|
| Language | TypeScript | Python |
| Style | OOP, decorators | Functional |
| Docs | Manual Swagger | Auto /docs |
| Performance | Good | Excellent |
When to use each
- NestJS: Large teams, microservices
- FastAPI: AI/ML, fast prototypes