1.2.0 • Published 6 years ago

lambda-api-gateway-response v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

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      DescriptionDefault value
statusSet HTTP status code200
headersSet response headers-
bodySet response bodynull
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.

1.2.0

6 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago