Recall & Review
beginner
What is the purpose of the
@Controller decorator in NestJS?The <code>@Controller</code> decorator marks a class as a controller that can handle incoming HTTP requests and send responses. It groups related request handlers under a common route prefix.Click to reveal answer
beginner
How do you specify a route prefix using the
@Controller decorator?You pass a string to
@Controller('prefix'). This prefix is added before all routes defined in the controller's methods.Click to reveal answer
beginner
Can a NestJS controller class have multiple route handlers? How?Yes. Inside a controller class, you define multiple methods decorated with HTTP method decorators like
@Get(), @Post(), etc. Each method handles a different route or HTTP verb.Click to reveal answer
beginner
What happens if you use
@Controller() without any prefix string?The controller will handle routes starting from the root path
/. Its methods define the full route paths.Click to reveal answer
intermediate
How does NestJS use the
@Controller decorator internally?NestJS uses <code>@Controller</code> to register the class as a controller in its routing system. It reads the decorator metadata to map HTTP requests to the controller's methods.Click to reveal answer
What does the
@Controller('users') decorator do?✗ Incorrect
The string inside
@Controller() sets the route prefix for all routes in that controller.Which decorator is used inside a controller to handle GET requests?
✗ Incorrect
@Get() marks a method to handle HTTP GET requests.If a controller has
@Controller() with no prefix, what is the base route?✗ Incorrect
No prefix means the base route is the root path
/.Can a single NestJS controller handle multiple HTTP methods?
✗ Incorrect
A controller can have many methods each decorated with different HTTP method decorators.
What is the main role of the
@Controller decorator in NestJS?✗ Incorrect
@Controller registers the class as a handler for HTTP routes.Explain how the
@Controller decorator works in NestJS and how it helps organize routes.Think about how a controller groups related web routes under one roof.
You got /4 concepts.
Describe how you would create a NestJS controller that handles GET requests at '/products' and POST requests at '/products'.
Focus on the decorator usage for the class and methods.
You got /4 concepts.