import { Controller, Get } from '@nestjs/common'; @Controller('users') export class UsersController { @Get() findAll() { return 'List of users'; } }
The @Controller('users') decorator sets the base route path to /users. The @Get() decorator on findAll() means it handles GET requests at the base path, so the full route is /users.
Option A misses parentheses after @Get. Decorators must be called as functions, so @Get() is required. This causes a syntax error.
import { Controller, Get } from '@nestjs/common'; @Controller('api/items') export class ItemsController { @Get() getItems() { return { count: 3, items: ['a', 'b', 'c'] }; } }
The getItems() method returns an object with count and items. NestJS automatically converts this to JSON in the HTTP response.
import { Controller, Get } from '@nestjs/common'; @Controller('tasks') export class TasksController { getTasks() { return 'Task list'; } }
In NestJS, methods must have decorators like @Get() to handle HTTP requests. Without it, the method is not exposed as a route.
@Controller('beta')
@Controller('alpha')
export class MultiController {
@Get()
getData() {
return 'data';
}
}In TypeScript, decorators are applied bottom-up. The last @Controller decorator overwrites the previous one. So only '/beta' is used as the base path.
