Controller Section of Overview needs clarity.
See original GitHub issueFor controllers, there was a lack of detail regarding the intended structure of the tutorial app that should be looked at.
For “Last Step,” I saw in the app.module.ts example that the CatsController was supposed to go in a folder called cats.
import { CatsController } from './cats/cats.controller';
I had it on the same level as app.module.ts, which I thought was intentional for the purposes of the Nest introduction.
It also isn’t clear what routes are generated based on the decorators.
The @Get() decorator tells Nest that it’s necessary to create an endpoint for this route path, and map every appropriate request to this handler. Since we declared the prefix for every route (cats), Nest will map every /cats GET request here.
So what does the route look like? /cats/findAll ??
If it’s just GET /cats, then what happens if I have more than one GET?
It isn’t clear whether the Observable streams are recommended or Async Await for controllers.
Is ‘body-parser’ installed with the TypeScript starter? I got an error until I installed with NPM.
Maybe I’m just being nitpicky. Still, these are concerns that are preventing me from moving on to Components. Mostly because I can’t seem to import cats.controller as a module.
Thanks.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top GitHub Comments
@arswaw it looks like the @Get() decorator takes a string path that will be appended to the path of the controller.
I.e. in a controller defined as
@Controller(‘/users’) @Get(‘/list’)
would respond to /users/list
With no path specified it defaults to ‘/’.
The decorator is defined here:. https://github.com/nestjs/nest/blob/master/src/common/utils/decorators/request-mapping.decorator.ts
The path string is whatever is used in express.
This can probably be better explained in the docs.
@kamilmysliwiec. Where is the repo for the docs? One of us could do a pull request for this.
Hi @arswaw @bkbonner The docs repo is public now https://github.com/nestjs/docs.nestjs.com Please feel free to create any pull requests based on your best judgment 😺 Appreciate each help. Thanks!