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.
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.
The @Post decorator defines a method to handle HTTP POST requests. Other decorators handle different HTTP verbs.
@Get('data') getData() { const data = this.service.fetchData(); // Missing return statement }
If the controller method does not return a value, NestJS cannot send a response, causing the client to wait indefinitely.
By default, NestJS creates a single instance of each controller (singleton) that handles all requests. This improves performance and resource use.
