Package Exports
- flow-api-engine
- flow-api-engine/dist/index.js
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 (flow-api-engine) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
๐ Flow API Engine
Flow API Engine is a lightweight Node.js library that enables developers to define and execute multi-step, dependency-aware API workflows using a single declarative flow definition.
Instead of manually chaining multiple REST API calls in code, Flow API Engine allows you to describe the execution flow, and the engine automatically handles:
- execution order
- dependency resolution
- data passing between APIs
๐ What Problem Does This Solve?
In real-world applications, a single feature often requires multiple API calls.
Traditional REST approach
Client โ API 1 โ API 2 โ API 3 โ Merge responses manuallyThis leads to:
- Multiple network requests
- Complex client or backend logic
- Hardcoded execution order
- Poor maintainability
Flow API approach
Client โ One Flow Definition โ Engine executes everythingโ Single request โ Automatic dependency handling โ Cleaner and more flexible architecture
โจ Key Features
- ๐ Dependency-aware execution using a DAG (Directed Acyclic Graph)
- ๐ Automatic data passing between APIs
- ๐งพ Declarative JSON flow definition
- ๐ HTTP API execution support
- ๐ง Transform nodes for data processing and aggregation
- โก Lightweight and easy to integrate with Node.js backends
๐ฆ Installation
npm install flow-api-engine๐ง Basic Usage
import { FlowEngine } from "flow-api-engine";
const engine = new FlowEngine();
const result = await engine.execute({
nodes: {
getUser: {
type: "http",
url: "https://jsonplaceholder.typicode.com/users/1"
},
extractUser: {
type: "transform",
depends_on: ["getUser"],
script: `
return {
name: context.getUser.name,
email: context.getUser.email
};
`
}
}
});
console.log(result);๐ค Output Example
{
"getUser": {
"id": 1,
"name": "Leanne Graham",
"email": "Sincere@april.biz"
},
"extractUser": {
"name": "Leanne Graham",
"email": "Sincere@april.biz"
}
}๐ Flow Definition Structure
{
"nodes": {
"<nodeId>": {
"type": "http | transform",
"depends_on": ["otherNodeId"],
"method": "GET | POST",
"url": "https://api.example.com",
"body": {},
"script": "JavaScript code"
}
}
}- Each node represents one execution step
depends_oncontrols execution order- Nodes run automatically when dependencies are satisfied
๐ Supported Node Types
1๏ธโฃ HTTP Node
Used to call REST APIs.
{
"type": "http",
"method": "POST",
"url": "https://api.example.com/order",
"body": {
"userId": "{{nodes.getUser.id}}",
"item": "Laptop"
}
}2๏ธโฃ Transform Node
Used to process, merge, or summarize data.
{
"type": "transform",
"depends_on": ["getUser"],
"script": "return { username: context.getUser.name };"
}๐ Data Passing Between Nodes (Core Concept)
Flow API Engine supports dynamic value substitution using templates:
{{nodes.<nodeId>.<property>}}Examples
Inside transform scripts
context.getUser.nameInside request bodies or URLs
"userId": "{{nodes.getUser.id}}"This allows one APIโs response to be used directly in another API call.
๐งช Example: Dependent POST Requests
engine.execute({
nodes: {
createUser: {
type: "http",
method: "POST",
url: "https://jsonplaceholder.typicode.com/users",
body: { name: "Zubair" }
},
createOrder: {
type: "http",
depends_on: ["createUser"],
method: "POST",
url: "https://jsonplaceholder.typicode.com/posts",
body: {
userId: "{{nodes.createUser.id}}",
product: "Laptop"
}
}
}
});๐งช Example: Better Long Example
await engine.execute({
nodes: {
user: {
type: "http",
url: "https://jsonplaceholder.typicode.com/users/1"
},
posts: {
type: "http",
depends_on: ["user"],
url: "https://jsonplaceholder.typicode.com/posts?userId={{nodes.user.id}}"
},
todos: {
type: "http",
depends_on: ["user"],
url: "https://jsonplaceholder.typicode.com/todos?userId={{nodes.user.id}}"
},
summary: {
type: "transform",
depends_on: ["posts", "todos"],
script: "return { totalPosts: context.posts.length, totalTodos: context.todos.length };"
}
}
});๐งฉ Internal Architecture (High Level)
FlowEngine
โโ Flow Executor
โโ Dependency Resolver (DAG)
โโ Context Store
โโ HTTP Node Executor
โโ Transform Executorโ ๏ธ Limitations
- Sequential execution only (parallel execution planned)
- Transform scripts are not sandboxed (trusted input recommended)
- Not intended for long-running workflows
๐ฎ Roadmap
- Parallel node execution
- Retry and timeout policies
- Conditional branching
- Secure transform sandbox
- Visual flow designer
๐ License
MIT License
โญ Summary
Flow API Engine simplifies backend orchestration by allowing developers to define what should happen, instead of hardcoding how API calls should be chained.