0
0
NestJSframework~10 mins

Route handlers (GET, POST, PUT, DELETE) in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a GET route handler in a NestJS controller.

NestJS
import { Controller, [1] } from '@nestjs/common';

@Controller('items')
export class ItemsController {
  @[1]()
  findAll() {
    return 'This action returns all items';
  }
}
Drag options to blanks, or click blank then click option'
ADelete
BPost
CPut
DGet
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Post instead of @Get for fetching data.
Forgetting to import the decorator.
2fill in blank
medium

Complete the code to create a POST route handler in a NestJS controller.

NestJS
import { Controller, Post } from '@nestjs/common';

@Controller('items')
export class ItemsController {
  @[1]()
  create() {
    return 'This action adds a new item';
  }
}
Drag options to blanks, or click blank then click option'
APost
BGet
CPut
DDelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Get instead of @Post for creating data.
Not importing the correct decorator.
3fill in blank
hard

Fix the error in the code by choosing the correct decorator for updating an item.

NestJS
import { Controller, [1] } from '@nestjs/common';

@Controller('items')
export class ItemsController {
  @[1](':id')
  update() {
    return 'This action updates an item';
  }
}
Drag options to blanks, or click blank then click option'
APost
BPut
CGet
DDelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Post instead of @Put for updates.
Using @Get for update operations.
4fill in blank
hard

Fill both blanks to create a DELETE route handler that deletes an item by id.

NestJS
import { Controller, [1] } from '@nestjs/common';

@Controller('items')
export class ItemsController {
  @[2](':id')
  remove() {
    return 'This action removes an item';
  }
}
Drag options to blanks, or click blank then click option'
ADelete
BGet
CPost
DPut
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Post or @Put instead of @Delete for removal.
Importing the wrong decorator.
5fill in blank
hard

Fill all three blanks to create a NestJS controller with GET, POST, and DELETE route handlers.

NestJS
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';
  }
}
Drag options to blanks, or click blank then click option'
AGet
BPost
CDelete
DPut
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to import one or more decorators.
Importing decorators not used in the controller.