lambda-api-gateway-response

1.2.0 • Public • Published

API Gateway Response builder for AWS Lambda

Build Status codecov Codacy Badge Maintainability

Install

NPM

npm i lambda-api-gateway-response

Usage

Chainable methods

Method Description Default value
status Set HTTP status code 200
headers Set response headers -
body Set response body null
send Invoke callback -

This

new ApiGatewayResponse(callback)
    .status(200)
    .headers({
        'access-control-allow-origin': '*'
    })
    .body({
        "foo": "bar"
    })
    .send();

will be send as:

{
    statusCode: 200,
    headers: {
        "access-control-allow-origin": "*"
    },
    body: {
        "foo": "bar"
    }
}

Example

var ApiGatewayResponse = require('lambda-api-gateway-response');
 
exports.myHandler = function(event, context, callback) {
 return new ApiGatewayResponse(callback)
    .status(200)
    .headers({
        'access-control-allow-origin': '*'
    })
    .body({
        "foo": "bar"
    })
    .send();
}

Contribute

If you have discovered a bug or have a feature suggestion, feel free to create an issue on Github.

/lambda-api-gateway-response/

    Package Sidebar

    Install

    npm i lambda-api-gateway-response

    Weekly Downloads

    1

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    5.67 kB

    Total Files

    6

    Last publish

    Collaborators

    • arjunkomath