express-crudl
About
Motivation for the module is to provide simple and consistent structure to controllers handling CREATE, READ, UPDATE, DELETE and LIST operations to resources and their subresources.
Example controller
exportsname = "test";exportssubresources = 'subroute': exports { ifreqparamstest_id Tests; else return ; }; exports { res;}; exports { Tests;};
And to use the controllers:
var express = crudl = ; var app = ;app;// Will mount all the controllers to app and print the routes with verbose:true;console;
For an example directory structure for controllers see test/controllers
Api
Only has the one method for loading and mounting the routes, express-crudl(app, options);
options available are: verbose controller_path
Functions in controllers
.before(req, res, next)
Middleware that is executed before the routes and before subresources.
.error(error, req, res, next)
Error handler for the route, if you want to have controller specific error handler.
.create(req, res, next)
The function executed for CREATE operation, ie POST /name
.read(req, res, next)
The function executed for READ operation, ie GET /name/:name_id
.update(req, res, next)
The function executed for UPDATE operation, ie PUT /name/:name_id
.del(req, res, next)
The function executed for DELETE operation, ie DELETE /name/:name_id
.list(req, res, next)
The function executed for LIST operation, ie GET /name
Variables in controllers
.subresources
Object mapping the subresources in name:module pairs {'name': require('./name')}
.prefix
prefix this controller under this path, exports.prefix = '/resource'; exports.name = 'sub'; maps the controller to '/resource/:resource_id/sub';
.name
overrides the name of the controller, by default the file/directory name is used.
.options
options are .set(key, value) to the app created for handling the routes.
Notes
Inspired by express-mvc