botify-labs / botify-sdk-js-middlewares

2 stars 1 forks source link

botify-sdk-middlewares

NPM Version Build Status

This package contains multiple middlewares allowing to customize and optimize Botify SDK's behaviour. Including local storage caching, request dedupling, api result post processing.

Installation

npm install --save botify-sdk-middlewares

You’ll also need the Botify SDK (core).

npm install --save botify-sdk

UMD bundle

An UMD bundle is available in dist/botify-sdk-middlewares.min.js. It means you can use the lib with any module loader, including Browserify and RequireJS. It exposes the global variable BotifySDKMiddlewares.

<script src="https://github.com/botify-labs/botify-sdk-js-middlewares/raw/master/node_modules/botify-sdk-middlewares/dist/botify-sdk-middlewares.min.js"></script>

Usage

Use applyMiddleware function to apply middlewares you need.

import { applyMiddleware, apiErrorMiddleware, lscacheMiddleware } from 'botify-sdk-middlewares';
import baseSdk from 'botify-sdk';

const sdk = applyMiddleware(
  apiErrorMiddleware,
  lscacheMiddleware()
)(baseSdk);

<!> Becareful: order maters. (read middleware's documentation requirement section).

Documentation

Note: examples are written with ES6 syntax but nothing prevents you to use this lib (and create middlewares) with plain old school JavaScript.

Commands

Influences

The middleware pattern used in this package has been greatly inspired by Redux middlewares.