@mooncake-dev/lambda-body-parser

1.0.4 • Public • Published

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.

Package Sidebar

Install

npm i @mooncake-dev/lambda-body-parser

Weekly Downloads

7

Version

1.0.4

License

MIT

Unpacked Size

3.96 kB

Total Files

4

Last publish

Collaborators

  • danillouz
  • dinostheo