Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
@middy/http-json-body-parser
Advanced tools
Http JSON body parser middleware for the middy framework
@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.
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 };
body-parser is a Node.js middleware for parsing incoming request bodies in a middleware before your handlers, available under the `req.body` property. It supports various content types including JSON, URL-encoded, and raw data. Unlike @middy/http-json-body-parser, which is specifically designed for AWS Lambda, body-parser is more general-purpose and can be used in any Node.js application.
lambda-middleware is a collection of middleware for AWS Lambda functions, similar to Middy. It includes a JSON body parser middleware that provides similar functionality to @middy/http-json-body-parser. However, lambda-middleware offers a broader set of middleware options for various use cases.
HTTP json body parser middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda
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.
To install this middleware you can use NPM:
npm install --save @middy/http-json-body-parser
JSON.parse
ing the body.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'})
})
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-2018 Luciano Mammino and the Middy team.
FAQs
Http JSON body parser middleware for the middy framework
The npm package @middy/http-json-body-parser receives a total of 0 weekly downloads. As such, @middy/http-json-body-parser popularity was classified as not popular.
We found that @middy/http-json-body-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
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.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.