@omerdev/fetch-craft
v1.0.0
Published
Resilient, type-safe modern HTTP client with automatic retries, timeouts, interceptors, and zero dependencies
Maintainers
Readme
🚀 @omerdev/fetch-craft
Resilient, type-safe modern HTTP client with automatic retries, timeouts, interceptors, and zero dependencies.
⚡ Why fetch-craft?
- Zero dependencies (Built on native Web Fetch standard).
- Auto Retry with Backoff: Seamless recovery from network hiccups and 5xx errors.
- Built-in Timeouts: Automatically aborts hanging requests.
- Interceptors: Clean request and response middleware pipeline.
- Type-Safe JSON: Automatic JSON parsing with
res.datatyping. - Cross-Platform: Works in Node.js 18+, Bun, Deno, and modern browsers.
📦 Installation
npm install @omerdev/fetch-craft
# or
pnpm add @omerdev/fetch-craft
# or
bun add @omerdev/fetch-craft💡 Quick Start
import { createClient } from "@omerdev/fetch-craft";
const api = createClient({
baseURL: "https://api.example.com",
timeout: 5000,
retry: {
attempts: 3,
delayMs: 1000,
backoff: 2
}
});
// Request interceptor (e.g. Auth header)
api.useRequest((opts) => {
opts.headers["Authorization"] = `Bearer ${myToken}`;
return opts;
});
// Type-safe GET
interface User {
id: string;
name: string;
}
const response = await api.get<User>("/users/me");
console.log(response.data.name);
// POST request with JSON body
const created = await api.post("/items", { name: "Gadget", price: 99 });👤 Author
omerdev
📄 License
MIT
