aws-lambda-response-builder
A Node.js module that helps you easily creates AWS Lambda responses.
Installation
npm install aws-lambda-response-builder --saveyarn add aws-lambda-response-builder
Contributing
Please read our contributing page
Usage
JavaScript
Without body
var responseBuilder = ; var okResponse = responseBuilder;
It will create a response such as:
{
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,
"Content-Type": "application/json"
},
body: '{}'
}
With body
var responseBuilder = ; var okResponse = responseBuilder;
It will create a response such as:
{
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,
"Content-Type": "application/json"
},
body: '{\"message\":\"some message\"}'
}
Without CORS headers
var responseBuilder = ; var okResponse = responseBuilder;
It will create a response such as:
{
statusCode: 200,
headers: { },
body: '{}'
}
TypeScript
Without body
; ;
It will create a response such as:
{
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,
"Content-Type": "application/json"
},
body: '{}'
}
With body
; ;
It will create a response such as:
{
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,
"Content-Type": "application/json"
},
body: '{\"message\":\"some message\"}'
}
Without CORS headers
; ;
It will create a response such as:
{
statusCode: 200,
headers: { },
body: '{}'
}
Using the builder
; .withCors .withHeader"dummyHeaderKey", "dummyHeaderValue" .build;
Scripts
ESLint
Check linting errors
npm run eslint:checkyarn eslint:check
Fix linting errors
npm run eslint:fixyarn eslint:fix
Test
npm run testyarn test
Test with coverage
npm run test:coverageyarn test:coverage