A lightweight Node.js library to execute dependency-aware API workflows using a single declarative flow definition.
npm install flow-api-engineFlow 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
---
In real-world applications, a single feature often requires multiple API calls.
``text`
Client โ API 1 โ API 2 โ API 3 โ Merge responses manually
This leads to:
* Multiple network requests
* Complex client or backend logic
* Hardcoded execution order
* Poor maintainability
---
`text`
Client โ One Flow Definition โ Engine executes everything
โ Single request
โ Automatic dependency handling
โ Cleaner and more flexible architecture
---
* ๐ 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
---
`bash`
npm install flow-api-engine
---
`ts
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);
`
---
`json`
{
"getUser": {
"id": 1,
"name": "Leanne Graham",
"email": "Sincere@april.biz"
},
"extractUser": {
"name": "Leanne Graham",
"email": "Sincere@april.biz"
}
}
---
`json`
{
"nodes": {
"
"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_on controls execution order
* Nodes run automatically when dependencies are satisfied
---
Used to call REST APIs.
`json`
{
"type": "http",
"method": "POST",
"url": "https://api.example.com/order",
"body": {
"userId": "{{nodes.getUser.id}}",
"item": "Laptop"
}
}
---
Used to process, merge, or summarize data.
`json`
{
"type": "transform",
"depends_on": ["getUser"],
"script": "return { username: context.getUser.name };"
}
---
Flow API Engine supports dynamic value substitution using templates:
`text`
{{nodes.
Inside transform scripts
`ts`
context.getUser.name
Inside request bodies or URLs
`json`
"userId": "{{nodes.getUser.id}}"
This allows one APIโs response to be used directly in another API call.
---
`ts`
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"
}
}
}
});
---
`ts`
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 };"
}
}
});
---
```
FlowEngine
โโ Flow Executor
โโ Dependency Resolver (DAG)
โโ Context Store
โโ HTTP Node Executor
โโ Transform Executor
---
* Sequential execution only (parallel execution planned)
* Transform scripts are not sandboxed (trusted input recommended)
* Not intended for long-running workflows
---
* Parallel node execution
* Retry and timeout policies
* Conditional branching
* Secure transform sandbox
* Visual flow designer
---
MIT License
---
Flow API Engine simplifies backend orchestration by allowing developers to define what should happen, instead of hardcoding how API calls should be chained.