npm.io
0.2.4 • Published 4 years ago

@honestdoor/lambda-utils

Licence
ISC
Version
0.2.4
Deps
2
Size
16 kB
Vulns
1
Weekly
0

@honestdoor/lambda-utils

Collection of helpful utilities around working with lambda functions

Response Builder

The Responder is meant to make api gateway responses easier to write and manage

Example Usage:

import { Responder } from '@honestdoor/lambda-utils'

const res = new Responder({
    // Default response variables
    headers: {
        "Access-Control-Allow-Origin": "locahost:3000"
    },
    statusCode: 400
})

...

const response =  res.status(200).json({ success: true })

...

console.log(response)
Output:
{
  "headers": {
     "Access-Control-Allow-Origin": "locahost:3000"
  },
  "statusCode": 200,
  "body": "{ success: true }"
}

Error Example:

res.status(400).error("Something went terribly wrong!")