Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

koas-body-parser

remcohaszing3.9kMIT0.7.0TypeScript support: included

Koas body parser parses and validates request bodies based on the current operation.

koa, koas, oai, openapi

readme

Koas Body Parser

Koas body parser parses and validates request bodies based on the current operation.

Installation

npm install koa koas-body-parser koas-core

Usage

const Koa = require('koa');
const { bodyParser } = require('koas-body-parser');
const { koas } = require('koas-core');

const api = require('./api.json');

const app = new Koa();
app.use(
  koas(api, [
    bodyParser({
      parsers: {
        // Parsers
      },
    }),
  ]),
);

Options

Koas body parser accepts a mapping of mime types to parser functions. Wildcard mime types are supported as well. The parsers for the following mime types are supported by default:

  • application/json
  • multipart/form-data
  • text/plain

Note: multipart/form-date is parsed entirely so it can be validated and used easily later on. If the request should be streamed instead, pass a custom multipart/form-data parser.