Complete the code to create a GET route handler in a NestJS controller.
import { Controller, [1] } from '@nestjs/common'; @Controller('items') export class ItemsController { @[1]() findAll() { return 'This action returns all items'; } }
The @Get() decorator defines a GET route handler in NestJS.
Complete the code to create a POST route handler in a NestJS controller.
import { Controller, Post } from '@nestjs/common'; @Controller('items') export class ItemsController { @[1]() create() { return 'This action adds a new item'; } }
The @Post() decorator defines a POST route handler used to create new resources.
Fix the error in the code by choosing the correct decorator for updating an item.
import { Controller, [1] } from '@nestjs/common'; @Controller('items') export class ItemsController { @[1](':id') update() { return 'This action updates an item'; } }
The @Put() decorator is used for updating existing resources in NestJS.
Fill both blanks to create a DELETE route handler that deletes an item by id.
import { Controller, [1] } from '@nestjs/common'; @Controller('items') export class ItemsController { @[2](':id') remove() { return 'This action removes an item'; } }
The @Delete() decorator is used to handle HTTP DELETE requests to remove resources.
Fill all three blanks to create a NestJS controller with GET, POST, and DELETE route handlers.
import { Controller, [1], [2], [3] } from '@nestjs/common'; @Controller('products') export class ProductsController { @Get() findAll() { return 'Return all products'; } @Post() create() { return 'Create a product'; } @Delete(':id') remove() { return 'Delete a product'; } }
Import all needed decorators: @Get(), @Post(), and @Delete() for the respective route handlers.