middy-autoproxyresponse
TypeScript icon, indicating that this package has built-in type declarations

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())

Readme

Keywords

none

Package Sidebar

Install

npm i middy-autoproxyresponse

Weekly Downloads

1,025

Version

0.1.0

License

MIT

Unpacked Size

2.12 kB

Total Files

4

Last publish

Collaborators

  • kennu
  • cloudeninc