middleware for express http response
$ npm install express-json-response
var express = require('express'),
expressResponse = require('express-json-response'),
app;
app = express();
app.use(expressResponse());
app.get('/', function(req, res) {
res.sendData({message: 'example'});
});
// Available methods
// 2xx Success
res.sendOk()
res.sendCreated()
res.sendData()
// 4xx Client Error
res.sendBadRequest()
res.sendUnauthorized()
res.sendForbidden()
res.sendNotFound()
res.sendMethodNotAllowed()
res.sendConflict()
// 5xx Server Error
res.sendServerError()
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test