middytohof
v1.0.2
Published
Convert Middy middleware to chainable higher-order functions returning lambda handlers.
Downloads
1
Maintainers
Readme
const { middleware1, middleware2 } = require('middy/middlewares');
const middy = require('middy');
// This contains your primary business logic.
const myHandler = (event, context, callback) => {
callback(null, { iAm: 'a response' });
};
module.exports = {
myHandler: middy(myHandler)
.use(middleware1())
.use(middleware2()),
};
const { compose } = require('ramda');
const { middleware1, middleware2 } = require('middy/middlewares');
const middytohof = require('middytohof');
// This contains your primary business logic.
const myHandler = (event, context, callback) => {
callback(null, { iAm: 'a response' });
};
module.exports = {
// Without ramda.
myHandler: middytohof(middleware1())(
middytohof(middleware2())(
myHandler
)
),
// With ramda.
myHandlerWithRamda: compose(
middytohof(middleware1()),
middytoHof(middleware2())
)(myHandler),
};