Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/koa-bodyparser

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/koa-bodyparser

TypeScript definitions for koa-bodyparser

  • 3.0.21
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
268K
increased by0.77%
Maintainers
1
Weekly downloads
 
Created

What is @types/koa-bodyparser?

@types/koa-bodyparser provides TypeScript definitions for the koa-bodyparser middleware, which is used to parse the body of HTTP requests in Koa applications.

What are @types/koa-bodyparser's main functionalities?

Basic Usage

This code demonstrates the basic usage of koa-bodyparser. It sets up a Koa application, uses the bodyParser middleware to parse incoming request bodies, and then responds with the parsed body.

const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const app = new Koa();

app.use(bodyParser());

app.use(async ctx => {
  ctx.body = ctx.request.body;
});

app.listen(3000);

Custom Options

This code demonstrates how to use custom options with koa-bodyparser. It configures the middleware to parse JSON, form, and text bodies with specific size limits.

const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const app = new Koa();

app.use(bodyParser({
  enableTypes: ['json', 'form', 'text'],
  jsonLimit: '1mb',
  textLimit: '1mb',
  formLimit: '1mb'
}));

app.use(async ctx => {
  ctx.body = ctx.request.body;
});

app.listen(3000);

Error Handling

This code demonstrates how to handle errors in koa-bodyparser. It sets up a custom error handler that throws a 422 error if the body parsing fails.

const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const app = new Koa();

app.use(bodyParser({
  onerror: (err, ctx) => {
    ctx.throw('body parse error', 422);
  }
}));

app.use(async ctx => {
  ctx.body = ctx.request.body;
});

app.listen(3000);

Other packages similar to @types/koa-bodyparser

FAQs

Package last updated on 19 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc