Skip to content

Rest Pipeline JS ​

Flexible, modular pipeline orchestrator for REST APIs — sequential and parallel stages, retry with backoff, response caching, rate limiting, auth provider, stream stages (SSE / AsyncIterable), plugin system, and Vue / React integrations — all with a single dependency (axios).

Features ​

  • createRestClient() — full-featured HTTP client built on top of axios: retry with exponential backoff and Retry-After support, response caching with a pluggable CacheStore backend (incl. targeted invalidateCache()), rate limiting (concurrency + req/interval) with a pluggable distributed RateLimiterStore, circuit breaker with a pluggable distributed CircuitBreakerStore, auth provider with automatic 401 refresh and optional token caching, request cancellation by key, custom HTTP adapters
  • Request tracing — W3C traceparent header generation plus a TracingProvider hook (duck-typed against OpenTelemetry's Span API) for wiring in a real tracing backend
  • Idempotency keys — Idempotency-Key header on mutating requests, manual or auto-generated per logical request across retry attempts
  • Offline queue — queue mutating requests made while offline and replay them (same idempotency key on every attempt) once back online; pluggable persistence, isOnline/onOnlineChange for non-browser environments
  • PipelineOrchestrator — sequential and parallel stage execution; each stage has condition, before, request, after, validateInput, validateOutput, errorHandler hooks (all receive the pipeline's AbortSignal); sharedData pool shared across all stages
  • Error recovery — errorHandler can return recoverStep(data) to turn a failed stage back into a successful one and keep the pipeline going, instead of only transforming the error
  • Global middleware — beforeEach / afterEach / onError hooks that apply to every stage without modifying individual configs
  • Parallel groups — multiple stages run concurrently via Promise.all, or through a bounded pool via concurrency; single failure stops the group
  • Pause / Resume / Abort — pause() waits after the current stage; resume() continues; abort() cancels the current HTTP request and propagates its AbortSignal into every stage hook so custom request/before/after functions can cancel their own work too
  • Export / Import state — serialize stageResults + logs to a plain object; restore on the next page load
  • Stream stages — stream: async function* for SSE / any AsyncIterable; onChunk callback in real time; abort-aware
  • WebSocket stages — a stage over a persistent connection (onOpen/onMessage/onClose/onError, closeOn); pluggable createWebSocket (defaults to globalThis.WebSocket) for Node <22/edge runtimes
  • Pipeline metrics & run correlation — onPipelineStart, onPipelineEnd, onStepDuration callbacks, plus a runId (also on getRunId(), log entries, and step events) shared by every callback/event from the same run
  • createPipeline() / pipe() builder — short factory and fluent builder API for common patterns; in TypeScript, pipe().step() chains infer prev's type from the previous step automatically
  • validatePipelineConfig() — catch duplicate keys, empty keys, type errors before runtime
  • Plugin system — install reusable behavior (logging, analytics, etc.); cleanup via destroy()
  • Persist adapter — pluggable save/load interface; auto-save after each stage
  • Log sanitization — mask sensitive headers (authorization, x-api-key, cookie, …) in metrics callbacks, on by default
  • Vue integration — usePipelineRunVue, usePipelineProgressVue, and more (import from rest-pipeline-js/vue)
  • React integration — usePipelineRunReact, usePipelineProgressReact, and more (import from rest-pipeline-js/react)
  • paginate() / paginateAll() / flattenPages() — iterate a paginated API (cursor- or offset/limit-based) as an AsyncGenerator<T[]>, standalone or as a StreamStageConfig source
  • createMockAdapter() (separate rest-pipeline-js/testing entry point) — route-based HttpAdapter for testing code that uses this package without a real backend, with call history and sequenced responses for exercising retry
  • Tree-shakeable — sideEffects: false; Vue and React entry points are code-split