Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/serviejs/get-body
General HTTP request body parser
https://github.com/serviejs/get-body
body-parser buffer http json promises stream url-encoded
Last synced: about 1 month ago
JSON representation
General HTTP request body parser
- Host: GitHub
- URL: https://github.com/serviejs/get-body
- Owner: serviejs
- License: other
- Created: 2017-01-24T21:29:36.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-19T10:33:58.000Z (over 6 years ago)
- Last Synced: 2024-12-11T20:49:00.917Z (about 2 months ago)
- Topics: body-parser, buffer, http, json, promises, stream, url-encoded
- Language: TypeScript
- Size: 57.6 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Get Body
[![NPM version](https://img.shields.io/npm/v/get-body.svg?style=flat)](https://npmjs.org/package/get-body)
[![NPM downloads](https://img.shields.io/npm/dm/get-body.svg?style=flat)](https://npmjs.org/package/get-body)
[![Build status](https://img.shields.io/travis/serviejs/get-body.svg?style=flat)](https://travis-ci.org/serviejs/get-body)
[![Test coverage](https://img.shields.io/coveralls/serviejs/get-body.svg?style=flat)](https://coveralls.io/r/serviejs/get-body?branch=master)> General HTTP request body parser.
Looking for a multipart body parser? Try [`busboy`](https://www.npmjs.com/package/busboy).
## Installation
```
npm install get-body --save
```## Usage
```ts
import { parse, json, text, form } from 'get-body'
import { createServer } from 'http'createServer(function (req) {
parse(req, req.headers).then(body => console.log(body))
})
```### Arguments
1. `stream: Readable` An instance of the request stream
2. `headers: object` The raw headers object as a lower-cased map
3. `options: object` Parser configuration### Options
* `limit` Controls the maximum request body size (default: `100kb`).
* `decoders` Map of known `content-encoding` decoders (default: `exports.decoders`)
* `jsonParse` Custom behaviour for JSON parsing (default: strict `JSON.parse` check)
* `formParse` Custom behaviour for form parsing (default: `querystring.parse`)
* `jsonTypes` Array of media types to parse as JSON
* `formTypes` Array of media types to parse as a form
* `textTypes` Array of media types to parse as text## TypeScript
This project is written using [TypeScript](https://github.com/Microsoft/TypeScript) and publishes the definitions directly to NPM.
## License
Apache 2.0