/KoaBody

A simple body fetcher.

Primary LanguageJavaScriptMIT LicenseMIT

KoaBody

A simple body fetcher for Koa.

dependencies

setup

npm i @seregpie/koa-body

usage

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.

let body = await KoaBody.json(ctx);

Set an explicit limit.

let body = await KoaBody.json(ctx, {limit: '16mb'});

Fetch the body as text/plain. The default limit of the content length is 56kb.

let body = await KoaBody.text(ctx);

Detect the content type automatically.

let body = await KoaBody(ctx);