JSPM

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

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

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

Flow API Engine allows developers to define and execute multi-step API calls (with dependencies and data passing) in one flow, instead of manually chaining multiple REST calls.


๐Ÿ“ฆ Installation

npm install @your-username/flow-api-engine

Replace @your-username with your actual npm scope.


๐Ÿค” Why Flow API Engine?

Traditional REST APIs require multiple sequential requests:

Client โ†’ API 1 โ†’ API 2 โ†’ API 3 โ†’ Merge Logic

With Flow API Engine, you define the entire workflow once:

Client โ†’ Flow Definition โ†’ Engine Executes Everything

โœ” Fewer network calls โœ” Cleaner client code โœ” Centralized orchestration


โœจ Features

  • Dependency-aware execution (DAG based)
  • Automatic data passing between APIs
  • Declarative JSON flow definition
  • HTTP API execution support
  • Transform nodes for data processing
  • Easy integration with Node.js backends

๐Ÿง  Basic Usage

import { FlowEngine } from "@your-username/flow-api-engine";

const engine = new FlowEngine();

const result = await engine.execute({
  nodes: {
    getUser: {
      type: "http",
      method: "GET",
      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"
    }
  }
}

๐Ÿ”— 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 or merge data from previous nodes.

{
  "type": "transform",
  "depends_on": ["getUser"],
  "script": "return { username: context.getUser.name };"
}

๐Ÿ”„ Data Passing Between Nodes

Results of previous nodes are automatically available:

Inside transform scripts

context.getUser.name

Inside request bodies

"userId": "{{nodes.getUser.id}}"

๐Ÿงช 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"
      }
    }
  }
});

๐Ÿงฉ Internal Architecture (For Understanding)

FlowEngine
 โ”œโ”€ Flow Validator
 โ”œโ”€ 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 designed for long-running workflows

๐Ÿ”ฎ Roadmap

  • Parallel node execution
  • Retry & 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, not how to chain API calls.

Perfect for:

  • Microservices orchestration
  • Backend automation
  • Complex API workflows