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

http-body-parser

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-body-parser

🎨 A body parser for node, koa, koa2, express. support json, form, text, multipart and stream type body.

  • 1.1.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
95
increased by265.38%
Maintainers
1
Weekly downloads
 
Created
Source

http-body-parser

NPM version build status Coveralls David deps node version Gittip

🔥 A body parser for koa, express. support json, form, text, multipart and stream type body.

Install

NPM

Usage

Koa

const Koa = require('koa');
const bodyParser = require('http-body-parser').koa;

const app = new Koa();
app.use(bodyParser({}));

app.use(async ctx => {
  // the parsed body will store in ctx.request.body
  // if nothing was parsed, body will be an empty object {}
  ctx.body = ctx.request.body;
});

Express

const express = require('express');
const bodyParser = require('http-body-parser').express;

const app = express();
app.use(bodyParser({}));

server.use('/', function(req, res) {
  res.send(req.body)
})

Features

  • Based on the ES6 syntax, the code is concise
  • No third party module dependent
  • Support Koa and Express

Options

  • default options
{
    enableTypes: ['json', 'form', 'text', 'multipart', 'stream'],
    json: {
      limit: 1024*1024,
      strict: true,
      extendsTypes: []
    },
    text: {
      limit: 1024*1024,
      extendsTypes: []
    },
    form: {
      limit: 56*1024,
      extendsTypes: []
    },
    stream: {
      limit: 1024*1024,
      path: `the operating system's default directory`
    },
    multipart: {
      limit: 1024*1024,
      path: `the operating system's default directory`
    }
}
  • enableTypes: parser will only parse when request type hits enableTypes, default is ['json', 'form', 'text', 'multipart', 'stream'].
  • encode: requested encoding. Default is utf-8.
  • limit: limit of the body. If the body ends up being larger than this limit, a 413 error code is returned.
  • strict: when set to true, JSON parser will only accept arrays and objects. Default is true.
  • extendTypes: support extend types, eg: application/x-javascript
  • path: which folder the uploaded files should be stored, active on multipart, stream

Raw Body

You can access raw request body by ctx.request.rawBody

Keywords

FAQs

Package last updated on 15 May 2017

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