A wrapper for serverless handlers to prevent silly mistakes, based on middy
Simply wrap your serverless handler like this :
import handly from 'handly'
const handler = async (event, context, callback) => {
return {
statusCode: 200,
body: {
message: {
hello: 'world',
},
},
};
};
export default handly(handler)
Handly wraps useful middy middlewares as well as other middlewares made by me.
Adds queryStringParameters
and pathParameters
keys even though there are null to allow code such as to never throw :
event.pathParameters.userId
Normalize http headers, for example Content-type
becomes Content-Type
When Content-Type
is set to application/json
, this middleware parses the body automatically so that event.body
becomes an object
When Content-Type
is set to application/json
, this middleware parses the body automatically so that event.body
becomes an object
Same as jsonBodyParser for application/x-www-form-urlencoded
This one is not a middy middleware but a wrapper which will return a 500 http response when an uncaught exception is thrown. The default behavior is to return a 200 response…
Not official middy middleware. It automatically calls JSON.stringify on every response body. This is something mandatory with aws.
Hello, I am Julien vallini, an indie-maker. Follow me on twitter if you like my work.
Handly is MIT licensed.