lambda-api-gateway-response

API Gateway Response builder for AWS Lambda

Usage no npm install needed!

<script type="module">
  import lambdaApiGatewayResponse from 'https://cdn.skypack.dev/lambda-api-gateway-response';
</script>

README

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.