# jsendp

> JSend middleware (with JSON-P) for Connect and Express.

Latest version **2.1.0** (published 2018-12-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsendp
pnpm add jsendp
yarn add jsendp
bun add jsendp
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2018-12-19 |
| First published | 2014-04-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10 |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | John Flesch |
| Maintainers | flesch, kikobeats |
| Keywords | api, express, jsend, json, jsonp, rest, restful |

## Links

- npm: https://www.npmjs.com/package/jsendp
- Repository: https://github.com/flesch/jsendp
- Homepage: https://github.com/flesch/jsendp#readme
- Issues: https://github.com/flesch/jsendp/issues
- npm.io page: https://npm.io/package/jsendp

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.0 (latest) — 2018-12-19
- 2.0.0 — 2017-11-07
- 1.2.0 — 2016-01-24
- 1.1.0 — 2016-01-23
- 1.0.1 — 2014-04-18
- 1.0.0 — 2014-04-17

## README

# 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](http://labs.omniti.com/labs/jsend).

This was heavily inspired by [jsender](https://www.npmjs.org/package/jsender) and [express-jsend](https://www.npmjs.org/package/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.

```js
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:

```js
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](http://flesch.mit-license.org)

---
_Source: https://npm.io/package/jsendp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
