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

@middy/http-event-normalizer

Package Overview
Dependencies
Maintainers
9
Versions
224
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@middy/http-event-normalizer

Http event normalizer middleware for the middy framework

  • 1.0.0-alpha.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55K
decreased by-12.02%
Maintainers
9
Weekly downloads
 
Created
Source

Middy http-event-normalizer middleware

Middy logo

HTTP error handler middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda

npm version Known Vulnerabilities Standard Code Style Greenkeeper badge Chat on Gitter

If you need to access the query string or path parameters in an API Gateway event you can do so by reading the attributes in event.queryStringParameters and event.pathParameters, for example: event.pathParameters.userId. Unfortunately if there are no parameters for these parameter holders, the relevant key queryStringParameters or pathParameters won't be available in the object, causing an expression like event.pathParameters.userId to fail with the error: TypeError: Cannot read property 'userId' of undefined.

A simple solution would be to add an if statement to verify if the pathParameters (or queryStringParameters) exists before accessing one of its parameters, but this approach is very verbose and error prone.

This middleware normalizes the API Gateway event, making sure that an object for queryStringParameters and pathParameters is always available (resulting in empty objects when no parameter is available), this way you don't have to worry about adding extra if statements before trying to read a property and calling event.pathParameters.userId will result in undefined when no path parameter is available, but not in an error.

Install

To install this middleware you can use NPM:

npm install --save @middy/http-event-normalizer

Options

This middleware does not have any option

Sample usage

const middy = require('@middy/core')
const httpEventNormalizer = require('@middy/http-event-normalizer')

const handler = middy((event, context, cb) => {
  console.log(`Hello user ${event.pathParameters.userId}`) // might produce `Hello user #undefined`, but not an error
  cb(null, {})
})

handler.use(httpEventNormalizer())

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

Keywords

FAQs

Package last updated on 23 May 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