Express Funnel
Json API Routing for express, using middlewares. Suitable to use with promises.
The idea behind this is to just use next()
everytime we want to respond a request.
NOTE: Now using node-friendly-response. Main differences:
funnel.responses
to access all response functions using camelCase style.- To forward the response inside a promise to the default middleware of funnel, you have to use
funnel.forward()
function like this:.then(funnel.forward(action, data))
or avoiddata
parameter if you got it in the promise chain (see example).
Installation
npm install express-funnel
Usage
var funnel = ; /** * This object has predefined a lot of HTTP statuses as functions that receives a JSON as an input, * and returns another JSON for funnel to use when we call next(data) */var status = funnelresponses;var express = ;var Promise = ;var app = ; var router = express; { // work work!} router; app;
This basic example will respond 200 with {message: "hello world!"}
for every GET request to /
Note that we handle any error in the catch
of the promise. If the case is an error, it will respond 400 with a json describing it. Example: {error: [Error], reason: "something bad happens"}