Examples
Focused, copy-pasteable snippets for patterns that come up often but don't fit neatly into the main Overview walkthrough. Each file is self-contained and commented.
These import from "rest-pipeline-js" as a consumer would (after npm install rest-pipeline-js) — they are not run as part of this repo's test suite or build. For a runnable, interactive app instead, see the Demo.
| File | Shows |
|---|---|
pagination-fanout.ts | Fanning out many paginated requests in parallel with a concurrency cap, instead of opening hundreds of connections at once. |
pagination-stream.ts | paginate()/flattenPages()/paginateAll() — cursor- or offset-based pagination as an async iterator, standalone or as a StreamStageConfig source. |
edge-fetch-adapter.ts | A custom HttpAdapter built on native fetch, for Cloudflare Workers / Deno / other environments without Node's axios. |
file-upload.ts | FormData uploads with onUploadProgress/onDownloadProgress on the default axios transport, plus a sketch of implementing upload progress in a custom fetch-based adapter. |
sse-stream.ts | A StreamStageConfig step consuming a Server-Sent Events endpoint chunk by chunk. |
websocket-stage.ts | A WebSocketStageConfig step over a persistent connection — onOpen/onMessage/onClose/onError, closeOn, and a Node-<22 createWebSocket swap-in note. |
redis-cache-store.ts | A CacheStore backed by Redis, so cached responses are shared across multiple server instances instead of living in one process's memory. |
redis-rate-limiter-store.ts | A RateLimiterStore backed by Redis, so a rate limit is shared across server instances instead of each one enforcing its own (which multiplies the real-world limit by the instance count). |
proactive-rate-limit-throttling.ts | Using rateLimit.onRateLimitHeaders to throttle from X-RateLimit-*/RateLimit-* response headers before hitting a 429, instead of only reacting after the fact. |
redis-circuit-breaker-store.ts | A CircuitBreakerStore backed by Redis, so open/closed/half-open state is shared across server instances instead of each needing its own failureThreshold failures before opening. |
opentelemetry-tracing.ts | W3C traceparent header generation plus a TracingProvider hook (duck-typed against OpenTelemetry's Span API) for wiring in a real tracing backend, including correlating requests with a pipeline's runId. |
idempotent-mutations.ts | Sending an Idempotency-Key header on mutating requests, manually or auto-generated by RequestExecutor across retry attempts. |
zod-validation.ts | A withZodSchema() adapter turning a Zod (or structurally compatible) schema into PipelineStageConfig.validateInput/validateOutput. |
mock-adapter.ts | createMockAdapter() (from rest-pipeline-js/testing) for testing code that uses this package without a real backend — route matching, dynamic responses, and sequenced responses for exercising retry. |
offline-queue.ts | HttpConfig.offlineQueue — queueing mutating requests while offline and replaying them (with the same Idempotency-Key) once back online, with a localStorage-backed persistAdapter. |