0.0.7 • Published 10 years ago

api-response-middleware v0.0.7

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

api-response-middleware

Express.js response formatting middleware

Installation

$ npm install api-response-middleware

API

var responseMiddleware = require('api-response-middleware');
app.use(responseMiddleware(options)); //App is an Express.js app. Pass in options

Options

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!"
}

Methods

res.apiResponse(response)

res.apiError(err, message, code, forceFail)

res.apiNotFound(err, message)

res.apiNotAllowed(err, message)

0.0.7

10 years ago

0.0.6

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago