casper

Helpers and handlers for building APIs in express.

casper

Helpers and handlers for building jsonp APIs in express

The following examples assume this:

// express 'app' available 
var casper = require('casper');

Send a noop:

// res.jsonp({}) is sent 
app.get('/', casper.noop());

With custom data:

// res.jsonp({ hello: 'world' }) is sent 
app.get('/', casper.noop({
  hello: 'world'
}));

Send data from db with appropriate 200, 500 or 404:

app.get('/', function (reqres) {
  YourModel
    .find()
    .exec(casper.db(req, res));
});

Check for the presence of a particular URL parameter:

// calls next() becuase present 
app.get('/:testParam',
        casper.check.params('testParam'),
        casper.noop());

400 errors becuase of missing parameter

app.get('/',
        casper.check.params('testParam'),
        casper.noop());

npm install casper

MIT