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

koa-bodyparser

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-bodyparser

a body parser for Koa

  • 4.4.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is koa-bodyparser?

koa-bodyparser is a middleware for Koa that parses incoming request bodies in a middleware before your handlers, making it available under the `ctx.request.body` property. It supports parsing JSON, form, and text bodies.

What are koa-bodyparser's main functionalities?

JSON Body Parsing

This feature allows you to parse JSON bodies from incoming requests. The parsed data is available on `ctx.request.body`.

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

app.use(bodyParser());

app.use(async ctx => {
  if (ctx.method === 'POST') {
    ctx.body = `Received JSON data: ${JSON.stringify(ctx.request.body)}`;
  } else {
    ctx.body = 'Send a POST request with JSON data';
  }
});

app.listen(3000);

Form Body Parsing

This feature allows you to parse URL-encoded form bodies from incoming requests. The parsed data is available on `ctx.request.body`.

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

app.use(bodyParser());

app.use(async ctx => {
  if (ctx.method === 'POST') {
    ctx.body = `Received form data: ${JSON.stringify(ctx.request.body)}`;
  } else {
    ctx.body = 'Send a POST request with form data';
  }
});

app.listen(3000);

Text Body Parsing

This feature allows you to parse plain text bodies from incoming requests. The parsed data is available on `ctx.request.body`.

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

app.use(bodyParser({ enableTypes: ['text'] }));

app.use(async ctx => {
  if (ctx.method === 'POST') {
    ctx.body = `Received text data: ${ctx.request.body}`;
  } else {
    ctx.body = 'Send a POST request with text data';
  }
});

app.listen(3000);

Other packages similar to koa-bodyparser

Keywords

FAQs

Package last updated on 15 Mar 2023

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