npm.io
2.1.1 • Published 5 years ago

@celeri/middleware-pipeline

Licence
ISC
Version
2.1.1
Deps
0
Size
8 kB
Vulns
0
Weekly
0
$ 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');