Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

middy-autoproxyresponse

0.1.0 • Public • Published

Middy AutoProxyResponse Middleware

Copyright (C) Clouden 2018
Author Kenneth Falck kennu@clouden.net 2018

Overview

This Middy middleware lets you return simple JavaScript objects from Lambda function handlers and converts them into LAMBDA_PROXY 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())

Keywords

none

install

npm i middy-autoproxyresponse

Downloadsweekly downloads

1

version

0.1.0

license

MIT

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability