JSPM

middytohof

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q14834F
  • License MIT

Convert Middy middleware to chainable higher-order functions returning lambda handlers.

Package Exports

  • middytohof

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (middytohof) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

middytohof · Travis Documented with emdaer

Convert Middy middleware plugins to higher-order functions returning lambda handlers.

Why?

Middy facilitates a middleware pattern very similar to express but for lambda handlers. It encapsulates common functionality into individual plugins separate from the primary business logic of your lambda’s handler.

Middytohof is for those who want to benefit from the plugins written for the Middy community, but prefer a functional approach over the middleware pattern when it comes to decorating lambda handlers.

Here’s a quick comparison to give you an idea of the difference:

Middleware pattern with Middy

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()),
};

Functional pattern with Middy plugins through middytohof

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),
};

Either pattern is perfectly reasonable. Now you have the option to choose while keeping the excellent plugins created for the Middy community! 🎉

Installation

yarn add middytohof

OR

npm i --save middytohof

Contributors

Contributors
Peter Sieg

License

middytohof is MIT licensed.