2.1.0 • Published 5 years ago

jsendp v2.1.0

Weekly downloads
19
License
MIT
Repository
github
Last release
5 years ago

jsendp

jsendp is middleware to add:

  • res.success
  • res.fail
  • res.error

in Express and Connect apps. It works just like res.json and res.jsonp but wraps your response body in the JSend specification.

This was heavily inspired by jsender and express-jsend, however jsendp uses res.jsonp by default and lets you also special the HTTP status code.

Installation

npm install jsendp --save

Usage

Add jsendp like you would any other middleware.

const express = require('express')
const jsendp = require('jsendp')

const app = express()

app.use(jsendp())

app.get('/', function (req, res, next) {
  res.success({
    message: 'Hi, Mom!'
  })
})

app.listen(3000)

JSON-P is enabled by default, though you can disable it (reverting to res.json) by passing an options object to the middleware:

const express = require('express')
const jsendp = require('jsendp')

app.use(jsendp({ jsonp: false }))

API

jsendp adds the following methods to the res object:

res.success({statusCode, data, message})
res.fail({statusCode, data, message})
res.error({statusCode, data, message})

License

Released under the MIT License: http://flesch.mit-license.org

2.1.0

5 years ago

2.0.0

7 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.1

10 years ago

1.0.0

10 years ago