Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bbqsrc/koa-simple-body
A clean body parser for Koa v2
https://github.com/bbqsrc/koa-simple-body
body-parser koa
Last synced: about 1 month ago
JSON representation
A clean body parser for Koa v2
- Host: GitHub
- URL: https://github.com/bbqsrc/koa-simple-body
- Owner: bbqsrc
- License: mit
- Created: 2016-12-29T07:13:20.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-07T06:50:37.000Z (almost 8 years ago)
- Last Synced: 2024-11-08T11:56:17.314Z (3 months ago)
- Topics: body-parser, koa
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-simple-body
```
npm install koa-simple-body
```Coherent and consistent body parsing implementation for Koa v2.
Supports multipart, url-encoded and JSON data by default. Check the `index.js` for the specific MIME types.
Everything it doesn't understand is parsed as plain text.
## Usage
### Defaults
```javascript
const Koa = require("koa")
const bodyParser = require("bodyParser")const app = new Koa()
app.use(bodyParser())
app.use(ctx => {
// Print fields
console.log(ctx.request.fields)// Print files (formidable)
console.log(ctx.request.files)
})
```That's it!
### Extra options
```javascript
bodyParser({
useBuffer: true, // enables parsing text/* as a buffer
buffer: "50kb", // max buffer size
text: "50kb", // max text size
json: "100kb", // max json size
urlEncoded: "500kb", // max url-encoded size
multipart: {
// Formidable options object (some examples shown)
maxFieldsSize: 5 * 1024 * 1024, // 5mb// Allow array of files with 'multiple' attribute
multiples: true
}
})
```For more information on the `Formidable.IncomingForm` options available, see the
[felixge/node-formidable](https://github.com/felixge/node-formidable) repository.## Roadmap
### 2.0
- Add support for bubbling errors to middleware (feedback and suggestions for API encouraged)
- Ensure default size settings are coherent and best defaults## License
MIT - see LICENSE file.