# api-response-middleware

> Express middleware for response formatting

Latest version **0.0.7** (published 2016-04-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install api-response-middleware
pnpm add api-response-middleware
yarn add api-response-middleware
bun add api-response-middleware
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2016-04-28 |
| First published | 2016-01-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Adam Stern |
| Maintainers | adamastern |
| Keywords | api, response, rest, json, restful, endpoint, express |

## Links

- npm: https://www.npmjs.com/package/api-response-middleware
- Repository: https://github.com/adamastern/api-response-middleware
- Homepage: https://github.com/adamastern/api-response-middleware#readme
- Issues: https://github.com/adamastern/api-response-middleware/issues
- npm.io page: https://npm.io/package/api-response-middleware

## 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

- 0.0.7 (latest) — 2016-04-28
- 0.0.6 — 2016-03-30
- 0.0.4 — 2016-01-22
- 0.0.3 — 2016-01-22
- 0.0.2 — 2016-01-13
- 0.0.1 — 2016-01-13

## README

# api-response-middleware

Express.js response formatting middleware

## Installation

```sh
$ npm install api-response-middleware
```

## API

```js
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:
```json
{
    "status":"success",
	"payload":{}
}
```

##### Fail format:
```json
{
    "status":"fail",
	"message":"Oops!"
}
```

##### Error format:
```json
{
    "status":"error",
	"message":"Oops!"
}
```

# Methods

#### res.apiResponse(response)

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

#### res.apiNotFound(err, message)

#### res.apiNotAllowed(err, message)

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