Skip to content

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.

FileShows
pagination-fanout.tsFanning out many paginated requests in parallel with a concurrency cap, instead of opening hundreds of connections at once.
pagination-stream.tspaginate()/flattenPages()/paginateAll() — cursor- or offset-based pagination as an async iterator, standalone or as a StreamStageConfig source.
edge-fetch-adapter.tsA custom HttpAdapter built on native fetch, for Cloudflare Workers / Deno / other environments without Node's axios.
file-upload.tsFormData uploads with onUploadProgress/onDownloadProgress on the default axios transport, plus a sketch of implementing upload progress in a custom fetch-based adapter.
sse-stream.tsA StreamStageConfig step consuming a Server-Sent Events endpoint chunk by chunk.
websocket-stage.tsA WebSocketStageConfig step over a persistent connection — onOpen/onMessage/onClose/onError, closeOn, and a Node-<22 createWebSocket swap-in note.
redis-cache-store.tsA 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.tsA 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.tsUsing 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.tsA 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.tsW3C 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.tsSending an Idempotency-Key header on mutating requests, manually or auto-generated by RequestExecutor across retry attempts.
zod-validation.tsA withZodSchema() adapter turning a Zod (or structurally compatible) schema into PipelineStageConfig.validateInput/validateOutput.
mock-adapter.tscreateMockAdapter() (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.tsHttpConfig.offlineQueue — queueing mutating requests while offline and replaying them (with the same Idempotency-Key) once back online, with a localStorage-backed persistAdapter.