@celeri/middleware-pipeline

A generic library for creating middleware pipelines

Usage no npm install needed!

<script type="module">
  import celeriMiddlewarePipeline from 'https://cdn.skypack.dev/@celeri/middleware-pipeline';
</script>

README

$ npm install --save @celeri/middleware-pipeline

Import

ES6 Modules

import { MiddlewarePipeline } from '@celeri/middleware-pipeline';

CommonJS Modules

const { MiddlewarePipeline } = require('@celeri/middleware-pipeline');

Usage

const pipieline = new MiddlewarePipeline();

pipeline
    // Middlewares can be async functions to be awaited
    .use(async (url) => await httpGet(url))
    // Or they can be normal functions
    .use((body) => JSON.parse(body))
    // Error handling middleware can be placed with catch
    .catch({ error } => console.error(error))
    // A catch implies that the error was handled (unless it also throws),
    // so following middleware will still run
    .use(() => {
        // This runs regardless of whether the first two steps passed
    });

pipeline.run('http://www.example.com');