Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @middy/http-urlencode-body-parser with all npm packages installed. Try it out:

require("@middy/core/package.json"); // @middy/core is a peer dependency. var httpUrlencodeBodyParser = require("@middy/http-urlencode-body-parser")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@middy/http-urlencode-body-parser v1.1.0

Urlencode body parser middleware for the middy framework

Middy http-urlencode-body-parser middleware

Middy logo

HTTP URLencode body parser middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda

This middleware automatically parses HTTP requests with URL-encoded body (typically the result of a form submit).

Install

To install this middleware you can use NPM:

npm install --save @middy/http-urlencode-body-parser

Options

  • extended (boolean) (optional): if true will use qs to parse the body of the request. By default is set to false

Sample usage

const middy = require('@middy/core')
const httpUrlEncodeBodyParser = require('@middy/http-urlencode-body-parser')

const handler = middy((event, context, cb) => {
  cb(null, event.body) // propagates the body as response
})

handler.use(httpUrlEncodeBodyParser({extended: false}))

// When Lambda runs the handler with a sample event...
const event = {
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: 'frappucino=muffin&goat%5B%5D=scone&pond=moose'
}

handler(event, {}, (_, body) => {
  expect(body).toEqual({
    frappucino: 'muffin',
    'goat[]': 'scone',
    pond: 'moose'
  })
})

Middy documentation and examples

For more documentation and examples, refers to the main Middy monorepo on GitHub or Middy official website.

Contributing

Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.

License

Licensed under MIT License. Copyright (c) 2017-2018 Luciano Mammino and the Middy team.

FOSSA Status

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free