api-response-middleware
v0.0.7
Published
Express middleware for response formatting
Downloads
6
Maintainers
Readme
api-response-middleware
Express.js response formatting middleware
Installation
$ npm install api-response-middlewareAPI
var responseMiddleware = require('api-response-middleware');
app.use(responseMiddleware(options)); //App is an Express.js app. Pass in optionsOptions
The function takes an option options object that may contain any of the following keys:
failCodes
An array of HTTP status codes that should be treated as 'fail', instead of 'error' (more on this below)
Response formats
This middleware attaches a few new methods to the Express 'res' object. These methods will send a response in one of three formats - Success, Fail, or Error
Succcess format:
{
"status":"success",
"payload":{}
}Fail format:
{
"status":"fail",
"message":"Oops!"
}Error format:
{
"status":"error",
"message":"Oops!"
}