Socket
Socket
Sign inDemoInstall

@middy/http-json-body-parser

Package Overview
Dependencies
3
Maintainers
9
Versions
214
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@middy/http-json-body-parser


Version published
Maintainers
9
Install size
96.4 kB
Created

Package description

What is @middy/http-json-body-parser?

@middy/http-json-body-parser is a middleware for AWS Lambda functions that automatically parses JSON-encoded request bodies. It simplifies the process of handling JSON input in serverless applications by converting the body of incoming HTTP requests into a JavaScript object.

What are @middy/http-json-body-parser's main functionalities?

Automatic JSON Parsing

This feature automatically parses the JSON body of incoming HTTP requests and makes it available as a JavaScript object in `event.body`. This eliminates the need to manually parse the JSON string in each handler.

const middy = require('@middy/core');
const jsonBodyParser = require('@middy/http-json-body-parser');

const handler = middy((event, context) => {
  // event.body is now a parsed JSON object
  return {
    statusCode: 200,
    body: JSON.stringify({ message: 'Parsed body', data: event.body })
  };
});

handler.use(jsonBodyParser());

module.exports = { handler };

Other packages similar to @middy/http-json-body-parser

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 Known Vulnerabilities Standard Code Style Greenkeeper badge Chat on Gitter

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.

Install

To install this middleware you can use NPM:

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

Options

This middleware does not have any option

Sample usage

const middy = require('@middy/core')
const httpJsonBodyParser = require('@middy/http-json-body-parser')

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

handler.use(httpJsonBodyParser())

// invokes the handler
const event = {
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({foo: 'bar'})
}
handler(event, {}, (_, body) => {
  expect(body).toEqual({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-2018 Luciano Mammino and the Middy team.

FOSSA Status

Keywords

FAQs

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc