Nest: Controller Section of Overview needs clarity.

Created on 9 Oct 2017  路  5Comments  路  Source: nestjs/nest

For 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.

type

Most helpful comment

@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.

All 5 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.

@ Controller and @ Get should obviously be upper cased. I did this from phone and didn't nest it in code block. Sorry.

Hi @arswaw,
I'm sorry for the confusion with the documentation. Definitely, this section needs clarity, would try to do this asap.

@bkbonner the docs repo's not public now, but it has to be changed so we can improve it together 馃檪

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!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tronginc picture tronginc  路  3Comments

KamGor picture KamGor  路  3Comments

rafal-rudnicki picture rafal-rudnicki  路  3Comments

FranciZ picture FranciZ  路  3Comments

cojack picture cojack  路  3Comments