# http-body-parser

> 🎨 A body parser for node, koa, koa2, express. support json, form, text, multipart and stream type body.

Latest version **1.1.9** (published 2017-05-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install http-body-parser
pnpm add http-body-parser
yarn add http-body-parser
bun add http-body-parser
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.9 |
| Published | 2017-05-16 |
| First published | 2017-05-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | sunwei |
| Maintainers | eqfox |
| Keywords | node, http, koa, koa2, express, express4, async, await, promise, json, text, stream, form, query, file, upload, body, parser |

## Links

- npm: https://www.npmjs.com/package/http-body-parser
- Repository: https://github.com/eqfox/http-body-parser
- Homepage: https://github.com/eqfox/http-body-parser#readme
- Issues: https://github.com/eqfox/http-body-parser/issues
- npm.io page: https://npm.io/package/http-body-parser

## Dependencies (1)

- [uuid](https://npm.io/package/uuid.md) ^3.0.1

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

- 1.1.9 (latest) — 2017-05-16
- 1.1.8 — 2017-05-15
- 1.1.7 — 2017-05-15
- 1.1.6 — 2017-05-15
- 1.1.5 — 2017-05-15
- 1.1.4 — 2017-05-15
- 1.1.3 — 2017-05-15
- 1.1.2 — 2017-05-15
- 1.1.1 — 2017-05-08
- 1.1.0 — 2017-05-08

## README

http-body-parser
===============

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Coveralls][coveralls-image]][coveralls-url]
[![David deps][david-image]][david-url]
[![node version][node-image]][node-url]
[![Gittip][gittip-image]][gittip-url]

[npm-image]: https://img.shields.io/npm/v/http-body-parser.svg?style=flat-square
[npm-url]: https://npmjs.org/package/http-body-parser
[travis-image]: https://img.shields.io/travis/eqfox/http-body-parser.svg?style=flat-square
[travis-url]: https://travis-ci.org/eqfox/http-body-parser
[coveralls-image]: https://img.shields.io/coveralls/eqfox/http-body-parser.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/eqfox/http-body-parser?branch=master
[david-image]: https://img.shields.io/david/eqfox/http-body-parser.svg?style=flat-square
[david-url]: https://david-dm.org/eqfox/http-body-parser
[node-image]: https://img.shields.io/badge/node.js-%3E=_7.6-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[gittip-image]: https://img.shields.io/gittip/dead-horse.svg?style=flat-square
[gittip-url]: https://www.gittip.com/dead-horse/


🔥 A body parser for koa, express. support `json`, `form`, `text`, `multipart` and `stream` type body.

## Install

[![NPM](https://nodei.co/npm/http-body-parser.png?downloads=true)](https://nodei.co/npm/http-body-parser/)

## Usage

### Koa
```js
const Koa = require('koa');
const bodyParser = require('http-body-parser').koa;

const app = new Koa();
app.use(bodyParser({}));

app.use(async ctx => {
  // the parsed body will store in ctx.request.body
  // if nothing was parsed, body will be an empty object {}
  ctx.body = ctx.request.body;
});
```

### Express
```js
const express = require('express');
const bodyParser = require('http-body-parser').express;

const app = express();
app.use(bodyParser({}));

server.use('/', function(req, res) {
  res.send(req.body)
})
```

## Features
* Based on the ES6 syntax, the code is concise
* No third party module dependent
* Support Koa and Express

## Options

- default options
```js
{
    enableTypes: ['json', 'form', 'text', 'multipart', 'stream'],
    json: {
      limit: 1024*1024,
      strict: true,
      extendsTypes: []
    },
    text: {
      limit: 1024*1024,
      extendsTypes: []
    },
    form: {
      limit: 56*1024,
      extendsTypes: []
    },
    stream: {
      limit: 1024*1024,
      path: `the operating system's default directory`
    },
    multipart: {
      limit: 1024*1024,
      path: `the operating system's default directory`
    }
}
```
* **enableTypes**: parser will only parse when request type hits enableTypes, default is `['json', 'form', 'text', 'multipart', 'stream']`.
* **encode**: requested encoding. Default is `utf-8`.
* **limit**: limit of the body. If the body ends up being larger than this limit, a 413 error code is returned.
* **strict**: when set to true, JSON parser will only accept arrays and objects. Default is `true`.
* **extendTypes**: support extend types, eg:  `application/x-javascript`
* **path**: which folder the uploaded files should be stored, active on `multipart, stream`

## Raw Body

You can access raw request body by `ctx.request.rawBody`

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