Socket
Socket
Sign inDemoInstall

@middy/http-json-body-parser

Package Overview
Dependencies
1
Maintainers
3
Versions
213
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @middy/http-json-body-parser

Http JSON body parser middleware for the middy framework


Version published
Weekly downloads
151K
decreased by-2.28%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

Middy http-json-body-parser middleware

Middy logo

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

npm version npm install size GitHub Actions CI status badge
Standard Code Style Known Vulnerabilities Language grade: JavaScript Core Infrastructure Initiative (CII) Best Practices
Chat on Gitter Ask questions on StackOverflow

You can read the documentation at: https://middy.js.org/docs/middlewares/http-json-body-parser

This middleware automatically parses HTTP requests with a JSON body and converts the body into an object. Also handles gracefully broken JSON as UnprocessableEntity (422 errors) if used in combination with httpErrorHandler.

It can also be used in combination with validator as a prior step to normalize the event body input as an object so that the content can be validated.

If the body has been parsed as JSON, you can access the original body (e.g. for webhook signature validation) through the request.event.rawBody.

Install

To install this middleware you can use NPM:

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

Options

  • reviver (function) (default undefined): A reviver parameter may be passed which will be used JSON.parseing the body.

Sample usage

import middy from '@middy/core'
import httpHeaderNormalizer from '@middy/http-header-normalizer'
import httpJsonBodyParser from '@middy/http-json-body-parser'

const handler = middy((event, context) => {
  return {}
})

handler
  .use(httpHeaderNormalizer())
  .use(httpJsonBodyParser())

// invokes the handler
const event = {
  headers: {
    'Content-Type': 'application/json'  // It is important that the request has the proper content type.
  },
  body: JSON.stringify({foo: 'bar'})
}
handler(event, {}, (_, body) => {
  t.is(body,{foo: 'bar'})
})

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-2022 Luciano Mammino, will Farrell, and the Middy team.

FOSSA Status

Keywords

FAQs

Last updated on 25 Nov 2022

Did you know?

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc