@mooncake-dev/lambda-body-parser
v1.0.4
Published
AWS Lambda APIG proxy integration helper to parse an HTTP request body.
Downloads
12
Readme
Lambda body parser
AWS Lambda APIG proxy integration helper to parse an HTTP request body.
Installation
npm i @mooncake-dev/lambda-body-parser
API
The module exposes the following methods:
json(body)
Parameters:
| Name | Required | Type | Description | | ---- | -------- | ------ | ---------------------------- | | body | Yes | String | The JSON string to be parsed |
Returns:
Parsed JSON Object.
Usage
const bodyParser = require('@mooncake-dev/lambda-body-parser');
bodyParser.json('{"hello": "world"}');
Examples
'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
}
};
Publish
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.