https://github.com/kikobeats/http-body
Parse the stream body into text/json/buffer/urlencoded (437 bytes).
https://github.com/kikobeats/http-body
body-parser nodejs
Last synced: about 1 year ago
JSON representation
Parse the stream body into text/json/buffer/urlencoded (437 bytes).
- Host: GitHub
- URL: https://github.com/kikobeats/http-body
- Owner: Kikobeats
- License: mit
- Created: 2023-01-22T12:19:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-12-16T18:48:55.000Z (over 1 year ago)
- Last Synced: 2025-04-29T01:50:50.069Z (about 1 year ago)
- Topics: body-parser, nodejs
- Language: JavaScript
- Homepage:
- Size: 55.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# http-body

[](https://coveralls.io/github/Kikobeats/http-body)
[](https://www.npmjs.org/package/http-body)
> Parse the stream body into text/json/buffer/urlencoded (437 bytes).
## Install
```bash
$ npm install http-body --save
```
## Usage
```js
const { buffer, text, json, urlencoded } = require('http-body')
/* into buffer */
await buffer(req)
// =>
/* into text */
await text(req)
// => '{"price": 9.99}'
/* into json */
await json(req)
// => { price: '9.99' }
/* into URLSearchParams */
await urlencoded(req)
// => 'price=9.99'
```
The max body size allowed by default is 1 MB. That can be customize as second argument:
```js
const { buffer, text, json, urlencoded } = require('http-body')
const bytes = require('bytes')
await buffer(req, { limit: bytes('1mb')})
// => TypeError: body size (1112140) is over the limit (1048576)
```
## API
### text(req, options)
Converts request body to string.
### urlencoded(req, options)
Parses request body using `new URLSearchParams`.
### json(req, options)
Parses request body using `JSON.parse`.
### buffer(req, options)
Minimal body parsing without any formatting.
## Options
### limit
Type: `number`
Default: `1048576`
The max body size allowed.
If the request body exceeds it, it throws an error.
## License
**http-body** © [Kiko Beats](https://kikobeats.com), released under the [MIT](https://github.com/Kikobeats/http-body/blob/master/LICENSE.md) License.
Authored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/Kikobeats/http-body/contributors).
> [kikobeats.com](https://kikobeats.com) · GitHub [Kiko Beats](https://github.com/Kikobeats) · X [@Kikobeats](https://x.com/Kikobeats)