🦅 NestJS
Beginner
What is a Controller in NestJS?
Answer
A Controller in NestJS is a class decorated with @Controller() that handles incoming HTTP requests and returns responses. Controllers define routes using method decorators: @Get(), @Post(), @Put(), @Delete(), @Patch(). Each method handles a specific HTTP request. Path parameters: @Param('id'). Request body: @Body(). Query strings: @Query(). Headers: @Headers(). Controllers are thin — they should only handle HTTP concerns and delegate business logic to Services. The controller class prefix in @Controller('users') sets the base path for all routes in that controller.