Skip to content

AWS Lambda APIG proxy integration helper to parse an HTTP request body.

License

Notifications You must be signed in to change notification settings

mooncake-dev/lambda-body-parser

Repository files navigation

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.

About

AWS Lambda APIG proxy integration helper to parse an HTTP request body.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published