Have ideas to improve npm?Join in the discussion! »

express-jefferson

1.1.3 • Public • Published

Build Status Coverage Status Code Climate Dependency Status

NPM

express-jefferson

Declarative Express Application Wiring

express-jefferson is a microlibrary for declaratively describing RESTful services. Currently, it allows you to describe your service routes as a map.

// main.js
var express = require('express'),
    jefferson = require('express-jefferson'),
    app = express(),    
    conf = {
        proxies: [
            {
                name: 'Logger',
                init (delegate) {
                    return (req, res, next) => {
                        console.log("invoking middleware function");
                        delegate(req, res, next);
                    }
                }
            }
        ],
        routes: {
            getBeerList: {
                method: 'GET',
                path: '/beers',
                middleware: [
                    beerlist.get
                    send.json
                ]
            }
        }
    };
    
jefferson(app, conf);
...

Configuration

  • routes: (optional) - An map of routes by name. Each object in the map describes an endpoint to be wired. These endpoints must contain an HTTP method, a path, and an array of middleware functions.
  • proxies: (optional) - An array of proxy objects invoked around all middleware functions in order. Each proxy object should have an init() function that accepts a delegate middleware function and returns a new middleware function.

Boilerplate Proxies

Promise-Based Middleware Proxy

require('express-jefferson/proxies/promise-handler')

This proxy accepts promise-based middleware (middleware that accepts two arguments) and wraps them in a promise chain before invoking next().

Installation

$ npm install express-jefferson --save

Keywords

Install

npm i [email protected]

Version

1.1.3

License

Apache

Last publish

Collaborators

  • avatar
  • avatar