Challenge - 5 Problems
NestJS Controller Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Role of Controllers in NestJS
In NestJS, why do controllers handle incoming HTTP requests?
Attempts:
2 left
💡 Hint
Think about what part of the app talks directly to the user requests.
✗ Incorrect
Controllers in NestJS map incoming HTTP requests to handler methods. They define routes and process requests to send back responses. They do not manage databases or UI rendering directly.
❓ component_behavior
intermediate2:00remaining
Controller Behavior on Incoming Request
What happens inside a NestJS controller when it receives an HTTP GET request to a defined route?
Attempts:
2 left
💡 Hint
Consider what a controller method does when a route is called.
✗ Incorrect
When a controller receives a request, it runs the method decorated for that route and returns a response. It does not skip processing or delay responses.
📝 Syntax
advanced2:00remaining
Correct Controller Method Decorator
Which decorator correctly defines a method in a NestJS controller to handle HTTP POST requests to the route '/create'?
Attempts:
2 left
💡 Hint
POST requests are used to create resources.
✗ Incorrect
The @Post decorator defines a method to handle HTTP POST requests. Other decorators handle different HTTP verbs.
🔧 Debug
advanced2:00remaining
Why Controller Method Does Not Respond
A NestJS controller method is defined but the client never receives a response. What is a likely cause?
NestJS
@Get('data') getData() { const data = this.service.fetchData(); // Missing return statement }
Attempts:
2 left
💡 Hint
Check if the method sends back data to the client.
✗ Incorrect
If the controller method does not return a value, NestJS cannot send a response, causing the client to wait indefinitely.
❓ lifecycle
expert2:00remaining
Controller Lifecycle and Request Handling
In NestJS, how often is a controller instance created to handle incoming HTTP requests by default?
Attempts:
2 left
💡 Hint
Think about how NestJS manages controller instances for performance.
✗ Incorrect
By default, NestJS creates a single instance of each controller (singleton) that handles all requests. This improves performance and resource use.