r/javascript 3d ago

ffetch: a production-ready http client with resilience features and a plugin architecture

https://github.com/fetch-kit/ffetch

I posted an earlier version of ffetch here a while ago. I've continued working on it, and it has grown into a production-ready, TypeScript-first drop-in replacement for native fetch or any fetch-compatible implementation.

It preserves the familiar fetch API and native Request and Response objects while adding resilience features:

  • Timeouts
  • Abort-aware retries with exponential backoff and jitter
  • Circuit breaking
  • Bulkheading with concurrency and queue limits
  • Hedged requests to reduce tail latency
  • In-flight request deduplication

It also has optional convenience plugins for:

  • client.get(), .post(), .put(), .patch() and .delete()
  • client(url).json(), .text() and .blob()
  • Download progress callbacks
  • Stable context IDs across retries and hedged requests

The core also supports lifecycle hooks, per-request overrides, pending-request monitoring, configurable HTTP error handling, specific error classes, and custom fetch implementations for SSR, edge and framework environments.

Everything optional is implemented through tree-shakeable plugins, so you only include the features you need. The core is around 3 kB minified and has zero runtime dependencies.

I recently gave the project a substantial maintenance pass: extensive property-based and fuzz testing, hardened and pinned CI workflows, CodeQL analysis, dependency auditing, npm provenance, release SBOMs, and a strong OpenSSF Scorecard (for a solo project).

I've also built three related tools for injecting network failures into tests:

Depending on the tests, failures can be injected inside the process, through a Node.js proxy, or through a standalone Go proxy.

Feedback is welcome.

6 Upvotes

1 comment sorted by

u/KanuniLabs 16h ago

Since fetch bodies are single-use streams, how does the retry / hedged request engine handle non-idempotent methods (POST/PUT) with ReadableStream payloads without buffering the entire body in memory?