restier
Express pluggable REST API, built in the right way. It always use a common convention in API responses, making the usage ideal for fast and secure development. You can use Promises, Callbacks, all what you want in single method call. It also supports MVC, using fancy controllers.
Features
- Express pluggable middleware.
- Common API response, using proper convention.
- Blazing fast development.
- Superb performance, due to its minimalist approach.
- Single point for responses, using dispatch method.
- Response support for plain objects, errors, callbacks and promises; suitable for all kind of servicing approach.
- Automatic exception capture, avoiding unexpected exceptions on production.
- High security with helmet support.
- Avoid all kind of chatty responses, hiding server tokens.
- Support for controllers, making architecture and maintenance better and frictionless.
- Understandable samples.
Quick Start
var restier = ;var api = ;var router = apirouter;var Promise = ; // Sample returning objectrouter; // Sample returning exceptionrouter; // Exception capturing, what????router; // Promise support, ohh this looks usefulrouter; // Support for legacy callbacks, uff I can't loose my async approach.router; // And what about controllers???router;// You'll have to dig more on this documentation, and samples. What are you waiting for? var app = ;// Yes you can plugit in your express app, even in a route.app; app;
Install
$ npm install restier
API
var restier = ;var api = ;
router
Returns the express router in which you must register the API routes.
Example
var router = apirouter;router;
Constructor ([options])
Returns restier object.
Options
restier()
accepts these properties in the options object.
poweredBy
Value for X-Powered-By header. Defaults to false
.
compression
Options for compression
module. Defaults to false
, or compression disabled.
helmet
Options for helmet
module. If false
passed, helmet will be disabled. If true
is passed helmet will be configured with helmet defaults. Otherwise helmet will be configured with your options.
cors
Options for cors
module. Defaults to false
, or cors disabled.
bodyParser
Options for bodyParser
module. If configuration is specified it will be merged with restier default options described below.
var defaultOptions = json: limit: '100kb' strict: true urlencoded: extended: true limit: '100kb' parameterLimit: 150 ;
methodOverride
Key to define header in which server must read real HTTP method to override actual method. It lets you use HTTP verbs such as PUT or DELETE in places you normally can't. Defaults to _method
.
router
Returns the express router in which you must register the API routes.
Example
var router = apirouter;router;
app
Returns an express app, to mount as middleware in route, or directly binds to interface.
Example
var app = ;app;app;
useControllers(controllersDir)
Returns a restier router, with routes mounted for controllers located in the specified directory. This method uses realpath for determining the correct path for looking out controllers.
router;
Controller Example
var Promise = ;var Controller = Controller; { Controller;} HomeControllerprototype { return hello: 'World';} HomeControllerprototype { var request = thisrequest; var promise = { ; }; return promise;} moduleexports = HomeController;
Tests
This is a work in progress
To run the test suite, first install the dependencies, then run npm test
:
$ npm install$ npm test
People
The original author of Restier is Carlos Luis Castro Márquez