Skip to content

sushilibdev/sushi-fetch

🍣 sushi-fetch

The lightweight, reactive powerhouse for modern data fetching.

NPM Version Bundle Size Downloads Stars

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 β€’ Report Bug β€’ Request Feature


πŸš€ 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

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.

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.

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.

const { data } = await sushi.get('/api/stats', { revalidate: true });

4. Real-time Progress (Streaming)

Tracking download/upload progress without messing with raw Streams.

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.

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