JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 24
  • Score
    100M100P100Q44299F
  • License MIT

A lightweight Node.js library to execute dependency-aware API workflows using a single declarative flow definition.

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

License: MIT

๐ŸŒŠ 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 manually

This 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_on controls 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.name

Inside 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.

Contact

https://www.linkedin.com/in/zubair-shareef