JSendie
JSendie is an Express middleware to provide structured JSON reponses
with 3 new methods - res.success
, res.fail
, and res.error
.
It is based on JSend specification (http://labs.omniti.com/labs/jsend).
Installation
npm install jsendie
Setup the middleware in your Express app. Before any routes.
var express = JSendie = app = PORT = 3000; // Remmeber to use it before any routesapp; app; app; // http://localhost:3000/success response body// {// "status": "success",// "data": {// "notice": "Hi, JSendie!"// }// }
Sample
https://github.com/kahwooi/jsendie/blob/master/test/server.js
API
JSendie adds the following methods to the res
methods:
res.success(data)
- data: Required success data.
res.fail(data)
- data: Required failure data. If the reasons for failure correspond to POST values, the response object's keys SHOULD correspond to those POST values.
res.error(message, code, data)
- message: Required error message.
- data: Optional error data.
- code: Optional error code.
License
This project is licensed under the MIT license. See the LICENSE file for more info.