nest-router-literal-colon
v0.0.1
Published
Provides a decorator for Nestjs controllers, to enable literal colon right after the controller path.
Downloads
4
Readme
Nest Routes With Literal Colon
Provides a decorator for Nestjs controllers, to enable literal colon right after the controller path.
Installation
npm i nest-router-literal-colon
Usage
// cats.controller.ts
@EnableLiteralColon
@Controller('cats')
export class CatsController {
constructor(private readonly catsService: CatsService) {}
@Post('(:)meow')
meow(@Body() meowCatDto: MeowCatDto) {
return this.catsService.meow(meowCatDto);
}
@Get()
findAll() {
return this.catsService.findAll();
}
@Get('(:)batchGet')
findByIds(@Query('ids') ids: string[]) {
return this.catsService.findByIds(ids);
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.catsService.findOne(id);
}
}
With the decorator, the routes will be:
POST cats:meow
GET cats
GET cats:batchGet
GET cats/:id
Without the decorator, the routes will be:
POST cats/(:)meow
GET cats
GET cats/(:)batchGet
GET cats/:id
Why
Read more about it here: Custom Methods For Rest APIs