Socket
Socket
Sign inDemoInstall

co-body

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-body

request body parsing for co


Version published
Weekly downloads
1.1M
increased by1.5%
Maintainers
3
Weekly downloads
 
Created

What is co-body?

The co-body npm package is a body parser for node.js that supports parsing JSON, form, and text bodies. It is designed to work with generators and promises, making it suitable for use with Koa and other async frameworks.

What are co-body's main functionalities?

Parse JSON body

This feature allows you to parse JSON bodies from incoming requests. The code sample demonstrates how to use co-body to parse a JSON body in a Koa application.

const coBody = require('co-body');
const Koa = require('koa');
const app = new Koa();

app.use(async (ctx) => {
  if (ctx.method === 'POST' && ctx.is('application/json')) {
    const body = await coBody.json(ctx.req);
    ctx.body = body;
  }
});

app.listen(3000);

Parse form-urlencoded body

This feature allows you to parse form-urlencoded bodies from incoming requests. The code sample demonstrates how to use co-body to parse a form-urlencoded body in a Koa application.

const coBody = require('co-body');
const Koa = require('koa');
const app = new Koa();

app.use(async (ctx) => {
  if (ctx.method === 'POST' && ctx.is('application/x-www-form-urlencoded')) {
    const body = await coBody.form(ctx.req);
    ctx.body = body;
  }
});

app.listen(3000);

Parse text body

This feature allows you to parse plain text bodies from incoming requests. The code sample demonstrates how to use co-body to parse a text body in a Koa application.

const coBody = require('co-body');
const Koa = require('koa');
const app = new Koa();

app.use(async (ctx) => {
  if (ctx.method === 'POST' && ctx.is('text/plain')) {
    const body = await coBody.text(ctx.req);
    ctx.body = body;
  }
});

app.listen(3000);

Other packages similar to co-body

Keywords

FAQs

Package last updated on 21 May 2018

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