https://github.com/seregpie/koabody
A simple body fetcher.
https://github.com/seregpie/koabody
Last synced: 2 months ago
JSON representation
A simple body fetcher.
- Host: GitHub
- URL: https://github.com/seregpie/koabody
- Owner: SeregPie
- License: mit
- Created: 2019-09-20T12:26:26.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-16T07:26:31.000Z (over 4 years ago)
- Last Synced: 2025-03-18T05:58:26.207Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# KoaBody
A simple body fetcher for Koa.
## dependencies
- [bytes](https://github.com/visionmedia/bytes.js)
## setup
```shell
npm i @seregpie/koa-body
```## usage
```javascript
let Koa = require('koa');
let KoaBody = require('@seregpie/koa-body');let app = new Koa();
app.use(async ctx => {
ctx.body = await KoaBody.json(ctx);
});
```---
Fetch the body as `application/json`. The default limit of the content length is 1mb.
```javascript
let body = await KoaBody.json(ctx);
```---
Set an explicit limit.
```javascript
let body = await KoaBody.json(ctx, {limit: '16mb'});
```---
Fetch the body as `text/plain`. The default limit of the content length is 56kb.
```javascript
let body = await KoaBody.text(ctx);
```---
Detect the content type automatically.
```javascript
let body = await KoaBody(ctx);
```