This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@donutteam/koa-body-parser
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

Koa Body Parser

A class for creating Koa middlewares that parse certain types of request bodies.

This is built on top of formidable V3.

Installation

Install the package with NPM:

npm install @donutteam/koa-body-parser

Usage

To use this class, simply instantiate an instance and add it to your Koa stack:

import Koa from "koa";

import { BodyParserMiddleware } from "@donutteam/koa-body-parser";

const app = new Koa();

const bodyParserMiddleware = new BodyParserMiddleware();

// Be sure to add the execute function on the instance
// and NOT the instance itself
app.use(bodyParserMiddleware.execute);

This will add a parsedBody object to context that will contain 4 fields:

  • fields: An object containing a key for every field in the request and the first value with that name.
  • fieldArrays: An object containing a key for every field in the request and an array of all values with that name.
  • files: An object containing a key for every file in the request and the first value with that name.
  • fileArrays: An object containing a key for every file in the request and an array of all values with that name.

This middleware supports parsing these types of incoming request bodies:

  • application/x-www-form-urlencoded
  • multipart/form-data
  • application/json

All other types will throw an error.

License

MIT

Package Sidebar

Install

npm i @donutteam/koa-body-parser

Weekly Downloads

0

Version

1.2.2

License

MIT

Unpacked Size

10.2 kB

Total Files

9

Last publish

Collaborators

  • duckdotexe