Middleware Integration Example
This example demonstrates how to use middleware in ZoopFlow to add cross-cutting concerns and functionality to your flows and steps.
What You'll Learn
- How to create and register middleware
- How to use middleware for input/output transformation
- How to implement cross-cutting concerns like logging, monitoring, and validation
- How to chain multiple middleware together
- How to implement specialized middleware like PII masking and encryption
Files in this Example
basic-middleware.ts- Shows the basic middleware patternpii-masking-middleware.ts- Implements a middleware for masking PII datamiddleware-chain.ts- Demonstrates chaining multiple middleware togethertag-processing-middleware.ts- Shows tag-based processing middlewarerun-example.ts- Entry point to run the example
Middleware Concepts
In ZoopFlow, middleware:
- Intercepts execution before and/or after steps or flows
- Can transform inputs and outputs
- Implements cross-cutting concerns like logging, tracing, and validation
- Enables advanced functionality like PII masking, encryption, and data transformation
- Can be combined and chained for complex processing
How to Run
# From the project root
npm install
npx ts-node docs/new-structure/examples/middleware-integration/run-example.tsExpected Output
The example will:
- Show middleware intercepting and modifying flow execution
- Demonstrate PII masking for sensitive data
- Show a chain of middleware applied in sequence
- Illustrate tag-based middleware processing
Output will show the transformations applied by each middleware.
Next Steps
- Create your own custom middleware for specific use cases
- Implement advanced middleware for data transformation or validation
- Combine middleware with schema validation in the Schema Validation Example
- Explore error handling in middleware with the Error Handling Example