Maps routes to CRUDL controllers for restfull routing


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. = "test";
exports.subresources = {
    'subroute': require('./subroute')
exports.before = function(reqresnext) {
  if(req.params.test_id) {
    Tests.load(req.params.test_id, function(errortest) {
      if(test) {
        req.test = test;
        return next();
      } else {
        return next(error || new Error("test "+req.params.test_id+" not found"));
  } else {
    return next();
}; = function(reqresnext) {
exports.create = function(reqresnext) {
  Tests.create(req.body, function(errtest) {
    if(err) {
      return next(err);
    } else {

And to use the controllers:

var express = require('express')
  , crudl = require('express-crudl');
var app = express();
app.set('controller path', __dirname + '/controllers/');
// Will mount all the controllers to app and print the routes with verbose:true 
crudl(app, {verbose: true});

For an example directory structure for controllers see test/controllers

Only has the one method for loading and mounting the routes, express-crudl(app, options);

options available are: verbose controller_path

Middleware that is executed before the routes and before subresources.

Error handler for the route, if you want to have controller specific error handler.

The function executed for CREATE operation, ie POST /name

The function executed for READ operation, ie GET /name/:name_id

The function executed for UPDATE operation, ie PUT /name/:name_id

The function executed for DELETE operation, ie DELETE /name/:name_id

The function executed for LIST operation, ie GET /name

Object mapping the subresources in name:module pairs {'name': require('./name')}

prefix this controller under this path, exports.prefix = '/resource'; = 'sub'; maps the controller to '/resource/:resource_id/sub';

overrides the name of the controller, by default the file/directory name is used.

options are .set(key, value) to the app created for handling the routes.

Inspired by express-mvc