All Projects â†’ nestjsx â†’ Nest Router

nestjsx / Nest Router

Licence: mit
Router Module For Nestjs Framework 🚦 🚀

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Nest Router

Nestjs Dialogflow
Dialog flow module that simplify the web hook handling for your NLP application using NestJS 📡
Stars: ✭ 51 (-87.34%)
Mutual labels:  nestjs, addons
Ramda Adjunct
Ramda Adjunct is the most popular and most comprehensive set of functional utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.
Stars: ✭ 550 (+36.48%)
Mutual labels:  utilities, addons
Core Nestjs
A simple application demonstrating the basic usage of permissions with NestJS (JWT, Passport, Facebook, Google+, User, Group, Permission)
Stars: ✭ 347 (-13.9%)
Mutual labels:  nestjs
Api
🏁🛠️ SaaS backend & API framework based on @nestjs
Stars: ✭ 390 (-3.23%)
Mutual labels:  nestjs
Nestjs Typeorm Paginate
📃 Pagination response object function + types for typeorm + nestjs
Stars: ✭ 377 (-6.45%)
Mutual labels:  nestjs
Go Keyring
Cross-platform keyring interface for Go
Stars: ✭ 351 (-12.9%)
Mutual labels:  utilities
Ca Archive
Catalog of classic Firefox add-ons created before WebExtensions apocalypse
Stars: ✭ 383 (-4.96%)
Mutual labels:  addons
Bigquery Utils
Useful scripts, udfs, views, and other utilities for migration and data warehouse operations in BigQuery.
Stars: ✭ 338 (-16.13%)
Mutual labels:  utilities
Craig S Utility Library
A giant set of utility classes originally start back in the .Net 2.0 days and updated until .Net Core and .Net Standard became a thing. At which point I took the library and broke it up into a ton of smaller libraries. View my profile for more up to date versions of everything.
Stars: ✭ 397 (-1.49%)
Mutual labels:  utilities
Leaa
Leaa is a monorepo restful CMS / Admin built with Nest.js (@nestjsx/crud, node.js) and Ant Design.
Stars: ✭ 375 (-6.95%)
Mutual labels:  nestjs
Docs.nestjs.com
The official documentation https://docs.nestjs.com 📕
Stars: ✭ 389 (-3.47%)
Mutual labels:  nestjs
Freecad Addons
A convenient gathering of useful and well-developed FreeCAD plugins made by the community.
Stars: ✭ 365 (-9.43%)
Mutual labels:  addons
Bull
Bull module for Nest framework (node.js) 🐮
Stars: ✭ 356 (-11.66%)
Mutual labels:  nestjs
Sharpkeys
SharpKeys is a utility that manages a Registry key that allows Windows to remap one key to any other key.
Stars: ✭ 4,402 (+992.31%)
Mutual labels:  utilities
Nest Next
Render Module to add Nextjs support for Nestjs
Stars: ✭ 348 (-13.65%)
Mutual labels:  nestjs
Docs.nestjs.cn
nestjs 中文文档
Stars: ✭ 393 (-2.48%)
Mutual labels:  nestjs
Ts Proto
An idiomatic protobuf generator for TypeScript
Stars: ✭ 340 (-15.63%)
Mutual labels:  nestjs
Nest Schedule
A cron-like and not-cron-like job distributed scheduler for Nest.js by decorators.
Stars: ✭ 368 (-8.68%)
Mutual labels:  nestjs
Nest Ideas Api
REST API for app ideas built in nestjs
Stars: ✭ 380 (-5.71%)
Mutual labels:  nestjs
Awesome Nestjs
A curated list of awesome things related to NestJS 😎
Stars: ✭ 5,032 (+1148.64%)
Mutual labels:  nestjs

Nest Router 🚦

Greenkeeper badge Build Status npm version Coverage Status FOSSA Status

Router Module For Nestjs Framework

Quick Overview

RouterModule helps you organize your routes and lets you create a routes tree.

How ?

Every module could have a path property. That path will be a prefix for all controllers in this module. If that module has a parent, it will be a child of it and again all controllers in this child module will be prefixed by parent module prefix + this module prefix

see issue #255 .

Install

IMPORTANT: you need Nest > v4.5.10+

npm install nest-router --save

OR

yarn add nest-router

Setup

See how easy it is to set up.

... //imports
const routes: Routes = [
    {
      path: '/ninja',
      module: NinjaModule,
      children: [
        {
          path: '/cats',
          module: CatsModule,
        },
        {
          path: '/dogs',
          module: DogsModule,
        },
      ],
    },
  ];

@Module({
  imports: [
      RouterModule.forRoutes(routes), // setup the routes
      CatsModule,
      DogsModule,
      NinjaModule
  ], // as usual, nothing new
})
export class ApplicationModule {}

👍 TIP: Keep all of your routes in a separate file like routes.ts

In this example, all the controllers in NinjaModule will be prefixed by /ninja and it has two childs, CatsModule and DogsModule.

Will the controllers of CatsModule be prefixed by /cats? NO!! 😮 The CatsModule is a child of NinjaModule so it will be prefixed by /ninja/cats/ instead. And so will DogsModule.

See examples folder for more information.

Example Folder Project Structure

.
├── app.module.ts
├── cats
│   ├── cats.controller.ts
│   ├── cats.module.ts
│   └── ketty.controller.ts
├── dogs
│   ├── dogs.controller.ts
│   ├── dogs.module.ts
│   └── puppy.controller.ts
├── main.ts
└── ninja
    ├── katana.controller.ts
    ├── ninja.controller.ts
    └── ninja.module.ts

And here is a simple, nice route tree of example folder:

ninja
    ├── /
    ├── /katana
    ├── cats
    │   ├── /
    │   └── /ketty
    ├── dogs
        ├── /
        └── /puppy

Nice!

Params in nested routes

In a standard REST API, you probably would need to add some params to your nested routes. Here is an example of how you can achieve it:

... //imports
const routes: Routes = [
    {
      path: '/ninja',
      module: NinjaModule,
      children: [
        {
          path: '/:ninjaId/cats',
          module: CatsModule,
        },
        {
          path: '/:ninjaId/dogs',
          module: DogsModule,
        },
      ],
    },
  ];

The ninjaId param will be available inside CatsModule controllers and DogsModule controllers. Please, find the instruction how to handle params in the official documentation. It might be a good practice to use a pipe for transformation use case to have an access to ninja object instead of just id.

Resolve Full Controller Path:

Nestjs dosen't resolve or take into account MODULE_PATH metadata when it is coming to resolve Controller path in Middleware resolver for example, so that i introduced a new fancy method RouterModule#resolvePath that will resolve the full path of any controller so instead of doing so:

consumer.apply(someMiddleware).forRoutes(SomeController);

you should do

consumer.apply(someMiddleware).forRoutes(RouterModule.resolvePath(SomeController));

see #32 for more information about this.

CHANGELOG

See CHANGELOG for more information.

Contributing

You are welcome to contribute to this project, just open a PR.

Authors

  • Shady Khalifa - Initial work

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].