resource-route
v0.2.0
Published
Human-readable JSON route definitions for REST resource models.
Downloads
1
Readme
resource-route
Human-readable JSON route definitions for REST resource models.
Installation
Install using npm:
npm install resource-route
Usage
var app = require('express')();
var route = require('resource-route')(app);
var User = require('./models/User');
route({
'/users': ['index', 'create', User],
'/users/:id': ['show', 'update', 'destroy', User]
});
With middleware:
route(authenticate, express.bodyParser(), {
'/users': ['index', 'create', User],
'/users/:id': ['show', 'update', 'destroy', User]
});
Using a model factory:
var route = require('resource-route')(app, function(name) {
return require('./models/' + name);
});
route({
'/users': ['index', 'create', 'User'],
'/users/:id': ['show', 'update', 'destroy', 'User']
});
Using a middleware factory:
var route = require('resource-route')(app,
// model factory
function(name) {
return require('./models/' + name);
},
// middleware factory
function(url, action, Model) {
return [
authenticate(Model),
express.bodyParser()
];
}
);
route({
'/users': ['index', 'create', 'User'],
'/users/:id': ['show', 'update', 'destroy', 'User']
});