fx-fetch
v1.1.2
Published
Simple, immutable, clonable, and effect-based HTTP fetching.
Maintainers
Readme
Fx-Fetch = Fetch × EffectTS
Simple, immutable, clonable, and effect-based HTTP fetching.
Introduction
A production-ready solution for safe & simple HTTP fetching built with EffectTS. Designed with great developer experience in mind. Works everywhere! Even in Firefox 🦊.
- ✅ Production-ready — Used in production by Ematiq since February 2025
- ✅ Immutable & Clonable — Follows functional programming principles
- ✅ Safe by default — Prevents common pitfalls with HTTP fetching
- ✅ Cross-platform — Works in all modern browsers, Bun, Deno, and Node.js
- ✅ Effect-based — Seamless integration with the Effect ecosystem
- ✅ Testable — Easy mocking and testing with service-based architecture
- ✅ Dual API — Familiar syntax from EffectTS
- ✅ Simple — It is just fetch! No more complex concepts to learn.
Documentation
📚 See our rich documentation site. It's worth it!
Installation
npm i fx-fetch # or pnpm, bun, denoQuick Example
import { Effect, Schema } from "effect";
import { Fetch, Request } from "fx-fetch";
class User extends Schema.Class<User>("User")({
id: Schema.Int,
firstName: Schema.String,
lastName: Schema.String,
}) {}
const getUser = Effect.fn(function* (id: number) {
const request = Request.unsafeMake({ url: `https://dummyjson.com/users/${id}` });
const payload = yield* Fetch.fetchJsonWithSchema(request, User);
// User ╶─┐
// ▼
return payload;
});Comparison with Other Solutions
| Solution | Immutable | Clonable | Effect-based | Production-ready |
| ------------------------------------------------------------------------------------------------------------------- | :-------: | :------: | :----------: | :--------------: |
| window.fetch ↗ | ❌ | ❌¹ | ❌ | ✅ |
| @effect/platform Http API ↗ | ✅ | ✅ | ✅ | ❌² |
| fx-fetch | ✅ | ✅ | ✅ | ✅ |
globalThis.RequestandglobalThis.Responseare not truly clonable. Why?- Marked as unstable in the official documentation. Some method implementations are still missing.
FAQ
Is it really production-ready?
Yes! We (Ematiq) have been using it in production since early February 2025.
Why are immutability and clonability important?
EffectTS is built on functional programming principles. All building blocks are immutable and clonable by design. For a library to truly be in symbiosis with EffectTS, it must adhere to the same principles.
Working with immutable objects can be challenging without proper tools — that's
why we built fx-fetch.
EffectTS excels at parallel actions and concurrent fibers. Without relying on immutable and clonable structures, you may encounter unexpected issues.
Real-world examples:
- Reusing the same
Requestfor paginated API calls - Appending general headers to already-created
Requestobjects - Retrying failed requests without worrying about side effects
Why aren't Request.clone() and Response.clone() enough?
[!CAUTION] First, they don't work properly in some browsers (looking at you, Firefox 🦊).
Even when they work correctly, they don't solve DX issues or provide key features like reading request/response properties multiple times without side effects.
const req = new globalThis.Request("url", {
method: "POST",
body: "Hello World", // ← String
});
// ReadableStream can only be read once. You must know what you're reading.
console.log(req.body); // → `ReadableStream { }`Sponsorship
OG Sponsor
The fx-fetch library was originally designed for TypeScript colleagues at Ematiq. Thanks to them for testing and feedback on early versions!
