https://github.com/sushilibdev/sushi-fetch
Modern data fetching made simple: caching, deduplication, retries, revalidation, and middleware in one tiny library.
https://github.com/sushilibdev/sushi-fetch
api-client cache data-fetching fetch http-client javascript swr typescript
Last synced: 4 months ago
JSON representation
Modern data fetching made simple: caching, deduplication, retries, revalidation, and middleware in one tiny library.
- Host: GitHub
- URL: https://github.com/sushilibdev/sushi-fetch
- Owner: sushilibdev
- License: mit
- Created: 2026-02-24T12:36:07.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-02-27T03:53:05.000Z (4 months ago)
- Last Synced: 2026-02-27T05:36:42.738Z (4 months ago)
- Topics: api-client, cache, data-fetching, fetch, http-client, javascript, swr, typescript
- Language: TypeScript
- Homepage:
- Size: 76.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# ðĢ sushi-fetch
**The lightweight, reactive powerhouse for modern data fetching.**
[](https://www.npmjs.com/package/sushi-fetch)
[](https://bundlephobia.com/package/sushi-fetch)
[](https://www.npmjs.com/package/sushi-fetch)
[](https://github.com/sushilibdev/sushi-fetch)
Tiny footprint. Zero dependencies. Enterprise-grade features.
Stop shipping 15kB+ of axios or tanstack-query for simple apps.
Get Smart Batching, Offline Persistence, SWR, and Reactivity in ~3kB (Gzipped).
[Explore Docs](#-api-reference) âĒ [Report Bug](https://github.com/sushilibdev/sushi-fetch/issues) âĒ [Request Feature](https://github.com/sushilibdev/sushi-fetch/issues)
---
## ð The v1.0.0 Evolution
Modern web apps need more than just `fetch()`. They need to survive poor networks, deduplicate aggressive UI renders, and keep data fresh automatically. Usually, you'd have to choose between "too barebones" (native fetch) or "too heavy" (GraphQL clients/TanStack).
**sushi-fetch v1.0.0** is the "Sweet Spot". We bring Silicon Valley-grade data synchronization to a ridiculously small footprint.
### âĻ The "Secret Sauce" (Features)
* ðĶ **[NEW] Smart Batching (Event Loop Deduplication)**: Prevents network spam. 10 identical requests in the same tick? Only 1 hits the server.
* ðū **[NEW] Offline Persistence**: Automatically dumps cache to `localStorage` (or custom adapters) and hydrates instantly on reload.
* ðĄ **[NEW] Auto-Polling & Focus Revalidation**: Keeps your UI feeling "alive". Data refetches automatically when the user switches tabs or on a set interval.
* ð§ **Smart Memory Cache**: Built-in TTL, sliding expiration, and LRU eviction.
* ð **SWR (Stale-While-Revalidate)**: Instant UI updates with background synchronization.
* ⥠**Reactive Pub/Sub**: Real-time state sync across your entire UI without needing Redux or Pinia.
* ð **Native Streaming**: Simple progress tracking for big uploads/downloads.
* ð **Smart Retries**: Fixed or Exponential Backoff strategies out of the box.
* ðŠķ **Zero Dependencies**: Pure, tree-shakable, strongly-typed TypeScript.
---
## ðĶ Installation
```bash
npm install sushi-fetch # or pnpm, yarn, bun
```
---
## ð The Magic (Quick Starts)
**1. The "Indestructible" Request (v1.0.0)**
Combine our most powerful features in a single, elegant call.
```ts
import { sushi } from 'sushi-fetch';
const data = await sushi.get('/api/dashboard', {
batch: true, // Groups simultaneous calls into one network request
revalidateOnFocus: true, // Silently updates data when user returns to the tab
pollInterval: 10000 // Keeps data fresh every 10 seconds
});
```
**2. Offline Persistence (Zero-Config Hydration)**
Keep your app working even when the signal drops. `sushi-fetch` handles the storage and hydration automatically.
```ts
import { SushiCache } from 'sushi-fetch';
// Setup persistent cache (Uses localStorage by default in browsers)
const persistentCache = new SushiCache({
persistKey: 'my-app-offline-db'
});
// Next time the user opens the app, data loads from disk in 0ms!
```
**3. The Power of SWR (Stale-While-Revalidate)**
Show the old data immediately, fetch the new one in the background. Your UI feels 10x faster.
```ts
const { data } = await sushi.get('/api/stats', { revalidate: true });
```
**4. Real-time Progress (Streaming)**
Tracking download/upload progress without messing with raw Streams.
```ts
await sushi.get('/api/large-file', {
onProgress: ({ percentage }) => console.log(`Downloading: ${percentage}%`),
});
```
---
## ð Comparison: No Bloat, Just Speed
| Feature | Native Fetch | Axios | **Sushi-Fetch** |
| :--- | :--- | :--- | :--- |
| **Size (Gzip)**| ~0kB | ~5.5kB | **~3.5kB** |
| **Caching** | â | â | â
(Built-in) |
| **Smart Batching** | â | â | â
(Auto) |
| **Offline Sync** | â | â | â
|
| **SWR** | â | â | â
|
| **Revalidation** | â | â | â
(On Focus / Interval) |
| **Streaming** | â (Hard) | â | â
(Simple) |
---
## âïļ Advanced: Global Instance & Interceptors
Create a pre-configured instance for your specific API, complete with middleware and auth interception.
```ts
import { createSushi } from 'sushi-fetch';
const api = createSushi({
baseUrl: '[https://api.myapp.com/v1](https://api.myapp.com/v1)',
interceptors: {
request: async (url, options) => {
options.token = getMySecretToken(); // Automatically attaches Bearer token
return options;
}
}
});
// Usage anywhere in your app:
const user = await api.get('/profile');
```
---
## ðĪ Support the Movement
This project is a labor of love for efficient, high-performance code. If sushi-fetch helped you build a faster app, please consider:
- Giving it a **Star** â (It helps others find the library!)
- Submitting an **Issue** if you find a bug.
- Sharing it on **Twitter/X** or **LinkedIn.**
---
## ð License
MIT ÂĐ sushilibdev