body-parser-multidict

Fork of body-parser with Werkzeug's MultiDict support for urlencoded forms

Usage no npm install needed!

<script type="module">
  import bodyParserMultidict from 'https://cdn.skypack.dev/body-parser-multidict';
</script>

README

body-parser-multidict

Build Status

Fork of body-parser with Werkzeug's MultiDict support for urlencoded forms

We built querystring-multidict for consistent typing when reading query strings (e.g. .get() always returns a single string value whereas querystring/qs can return an array/object depending on user input). Additionally, we added .fetch() to make throwing form validation errors easier.

Getting Started

This module can be installed via: npm install body-parser-multidict

Its usage is the same as body-parser:

// Load in our dependencies
var express = require('express');
var bodyParserMultiDict = require('body-parser-multidict');

// Create a new app using our urlencoded parser
var app = express();
app.use(bodyParser.urlencoded());

// Handle requests
app.use(function (req, res) {
  // Example request: `POST foo=bar&foo=baz`
  // First received value under key
  req.body.get('foo'); // 'bar'
  // Array of values received under key
  req.body.getArray('foo');// ['bar', 'baz']
});

Documentation

Documentation is the same as body-parser except req.body is a MultiDict. See querystring-multidict for MultiDict documentation:

https://github.com/twolfson/querystring-multidict/tree/1.1.0#multidict

License

MIT