middy-autoproxyresponse
v0.1.0
Published
Middy AutoProxyResponse Middleware
Downloads
4,147
Readme
Middy AutoProxyResponse Middleware
Copyright (C) Clouden 2018 Author Kenneth Falck [email protected] 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())