AWS Lambda APIG proxy integration helper to parse an HTTP request body.
npm i @mooncake-dev/lambda-body-parser
The module exposes the following methods:
Parameters:
Name | Required | Type | Description |
---|---|---|---|
body | Yes | String | The JSON string to be parsed |
Returns:
Parsed JSON Object.
const bodyParser = require('@mooncake-dev/lambda-body-parser');
bodyParser.json('{"hello": "world"}');
'use strict';
const bodyParser = require('@mooncake-dev/lambda-body-parser');
/**
* Lambda APIG proxy integration.
*
* @param {Object} event - HTTP input
*
* @return {Object} HTTP output
*/
module.exports.sendData = async event => {
try {
const body = bodyParser.json(event.body);
} catch (err) {
console.log('error: ', err); // eslint-disable-line no-console
}
};
For now we publish manually using:
npm publish --access public
Make sure:
- You increment the npm version after you make code changes with
npm version
. - You're logged in.
More information can be found here.