middy-autoproxyresponse

Middy AutoProxyResponse Middleware

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
middy-autoproxyresponse
0.1.04 years ago4 years agoMinified + gzip package size for middy-autoproxyresponse in KB

Readme

Middy AutoProxyResponse Middleware
Copyright (C) Clouden 2018
Author Kenneth Falck 2018

Overview

This Middy middleware lets you return simple JavaScript objects from Lambda function handlers and converts them into LAMBDAPROXY responses.
When you return a response like this:
{
  hello: 'world'
}
The AutoProxyRespose middleware converts it to this:
{
  statusCode: 200,
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    hello: 'world'
  })
}
If your response contains a statusCode attribute, it is not converted, allowing you to return a full LAMBDA
PROXY response manually.

Installation

To add the middleware to your project:
npm install --save middy-autoproxyresponse
To use the middleware in a Lambda function:
import { autoProxyResponse } from 'middy-autoproxyresponse'

async function handler(_event: any, _context: any) {
  return {
    hello: 'world'
  }
}

export default middy(handler)
.use(autoProxyResponse())