MΓ³dulo 05 Β· NestJS: Modules, Controllers, Services β LecciΓ³n 2 de 3 Β· ~8 min
Controllers map HTTP to methods
A controller is a routing table made of methods
In Express you called app.get("/walkers/:id", handler). In Nest the route lives on the method as a decorator, and the class groups every route under one path prefix:
@Controller("walkers")β every method in this class hangs off/walkers.@Get()on a method βGET /walkers.@Get(":id")βGET /walkers/:id.@Post()βPOST /walkers.@Param("id")pulls:idout of the path into a method argument.@Body()gives you the parsed JSON body.
The method's return value becomes the response body β Nest serializes it to JSON and sends 200 (or 201 for a @Post) for you. No res.json(), no res.status() in the common case.