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