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

@medley/body-parser

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@medley/body-parser

Essential body parsers for Medley.

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

@medley/body-parser

npm Version Build Status Coverage Status dependencies Status

Essential body parsers for Medley.

This module provides the following parsers:

Installation

# npm
npm install @medley/body-parser --save

# yarn
yarn add @medley/body-parser

API

const bodyParser = require('@medley/body-parser');

The bodyParser object exposes various factory functions that create a body-parsing function that should be passed as the second argument to Medley's app.addBodyParser() method. All factory functions take an options object for configuration.

The following describes each of the available factory functions.


bodyParser.json([options])

Parses request bodies as JSON using JSON.parse().

const bodyParser = require('@medley/body-parser');
const medley = require('@medley/medley');
const app = medley();

app.addBodyParser('application/json', bodyParser.json());
Options
limit
  • number
  • Default: 1048576 (1 MiB)

Specifies the maximum acceptable request body size.

bodyParser.json({limit: 100000})

bodyParser.text([options])

Parses request bodies into a string.

const bodyParser = require('@medley/body-parser');
const medley = require('@medley/medley');
const app = medley();

app.addBodyParser('text/plain', bodyParser.text());
// or
app.addBodyParser('text/*', bodyParser.text());
Options
limit
  • number
  • Default: 1048576 (1 MiB)

Specifies the maximum acceptable request body size.

bodyParser.text({limit: 100000})

bodyParser.urlEncoded([options])

Parses URL-encoded request bodies into an object.

const bodyParser = require('@medley/body-parser');
const medley = require('@medley/medley');
const app = medley();

app.addBodyParser('application/x-www-form-urlencoded', bodyParser.urlEncoded());
Options
limit
  • number
  • Default: 1048576 (1 MiB)

Specifies the maximum acceptable request body size.

bodyParser.urlEncoded({limit: 100000})
parser

Specifies the function that will parse the request body as a string into an object. This can be used as a way to call querystring.parse() with options.

const querystring = require('querystring');

function customParser(body) {
  return querystring.parse(body, null, null, {maxKeys: 20});
}

bodyParser.urlEncoded({parser: customParser})

bodyParser.buffer([options])

Parses request bodies into a Buffer.

const bodyParser = require('@medley/body-parser');
const medley = require('@medley/medley');
const app = medley();

app.addBodyParser('application/octet-stream', bodyParser.buffer());
// or to catch all requests
app.addBodyParser('*/*', bodyParser.buffer());
Options
limit
  • number
  • Default: 1048576 (1 MiB)

Specifies the maximum acceptable request body size.

bodyParser.buffer({limit: 100000})

Keywords

FAQs

Package last updated on 27 Mar 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