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 paths. This can happen when using path variables (ie /{name}/
) for an endpoint and the UI encodeURIComponent
the values before making the request.
To install this middleware you can use NPM:
npm install --save @middy/http-urlencode-path-parser
None
import middy from '@middy/core'
import httpUrlEncodePathParser from '@middy/http-urlencode-path-parser'
const handler = middy((event, context) => {
return event.body // propagates the body as response
})
handler.use(httpUrlEncodePathParser())
// When Lambda runs the handler with a sample event...
const event = {
pathParameters: {
name: encodeURIComponent('Mîddy')
}
}
handler(event, {}, (_, body) => {
t.deepEqual(body, {
name: 'Mîddy'
})
})
For more documentation and examples, refers to the main Middy monorepo on GitHub or Middy official website.
Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.
Licensed under MIT License. Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the Middy team.