API Gateway Response builder for AWS Lambda

Install

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.