node-rest-framework-pkg v2.1.4
node-rest-framework-pkg
Node Rest Framework provides some tools and helpers to enhance your experience using Node.js and Express. The project provides a way of structuring a project inspired by Django and Django Rest Framework in Python.
Install
npm install node-rest-framework-pkg --save
Use
Some explanations and examples are provided here for the main principles. Feel free to try them under the /examples folder in the sources.
Principles
The package exports the NRF class that must be instantiated and oconfigured. The, it can be used like a normal element with express using the "build" function.
Basic example
While configuring the NRF object, you can use the "add" and "addRouter" functions. add registers all elements that will be used later addRouter is the router configuration In the router, you can use the elements that you declared with add or declare it directly inline.
Usable elements
The types of elements used with add are : middlewares, permissions, validators, controllers. Middlewares are run first Permissions are there to ensure the user can access a given route Validators can validate post data and return error messages Controllers are the final request manader You can declare all these elements with add or use them directly in the router
Routing
Routing works like the express router. We can create routes and sub routes.
Models
You can declare models and use them to easily generate CRUD routes.
Project structure
This framework allows you to easily organize your code in segments. See the real case example in the sources.