1 | [![Build Status](https://travis-ci.org/atsid/express-jefferson.svg?branch=master)](https://travis-ci.org/atsid/express-jefferson)
|
2 | [![Coverage Status](https://coveralls.io/repos/atsid/express-jefferson/badge.svg)](https://coveralls.io/r/atsid/express-jefferson)
|
3 | [![Code Climate](https://codeclimate.com/github/atsid/express-jefferson/badges/gpa.svg)](https://codeclimate.com/github/atsid/express-jefferson)
|
4 | [![Dependency Status](https://david-dm.org/atsid/express-jefferson.svg)](https://david-dm.org/atsid/express-jefferson)
|
5 |
|
6 | [![NPM](https://nodei.co/npm/express-jefferson.png)](https://nodei.co/npm/express-jefferson/)
|
7 |
|
8 | # express-jefferson
|
9 | Declarative Express Application Wiring
|
10 |
|
11 | express-jefferson is a microlibrary for declaratively describing RESTful services. Currently, it allows you to describe your service routes as a map.
|
12 |
|
13 | ```js
|
14 | // main.js
|
15 | var express = require('express'),
|
16 | jefferson = require('express-jefferson'),
|
17 | app = express(),
|
18 | conf = {
|
19 | proxies: [
|
20 | {
|
21 | name: 'Logger',
|
22 | init (delegate) {
|
23 | return (req, res, next) => {
|
24 | console.log("invoking middleware function");
|
25 | delegate(req, res, next);
|
26 | }
|
27 | }
|
28 | }
|
29 | ],
|
30 | routes: {
|
31 | getBeerList: {
|
32 | method: 'GET',
|
33 | path: '/beers',
|
34 | middleware: [
|
35 | beerlist.get
|
36 | send.json
|
37 | ]
|
38 | }
|
39 | }
|
40 | };
|
41 |
|
42 | jefferson(app, conf);
|
43 | ...
|
44 | ```
|
45 |
|
46 | ## Configuration
|
47 | * 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.
|
48 | * 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.
|
49 |
|
50 | ## Boilerplate Proxies
|
51 | ### Promise-Based Middleware Proxy
|
52 | `require('express-jefferson/proxies/promise-handler')`
|
53 |
|
54 | This proxy accepts promise-based middleware (middleware that accepts two arguments) and wraps them in a promise chain before invoking next().
|
55 | ## Installation
|
56 |
|
57 | ```bash
|
58 | $ npm install express-jefferson --save
|
59 | ```
|