DEV Community

dev456456
dev456456

Posted on

๐Ÿš€ Fetchless โ€“ The New Era of HTTP Requests: Smart, Fast & Effortless

A lightweight and powerful alternative to Axios, Fetch, or node-fetch. Not just a wrapper โ€” a true evolution.


๐Ÿ” Why Fetchless?

Most HTTP libraries like axios or fetch do the bare minimum: send a request and return a response.
But modern web applications need more: performance, smart caching, robustness, resilience, and most of all... simplicity.

Fetchless delivers all of this with an HTTP API designed for 2025 โ€” combining lightness, intelligence, and automation.


โš™๏ธ Core Features

  • โœ… Efficient Caching: Stores HTTP responses to reduce network calls and boost speed.
  • โœ… Multiple Cache Strategies: Supports cache-first, network-first, and stale-while-revalidate modes.
  • โœ… TypeScript Support: Fully typed API for maximum reliability.
  • โœ… Ultra Lightweight: Minimal footprint with almost no dependencies.
  • โœ… Easy Integration: Works out of the box with any JS or TS project.

๐Ÿ”ฅ Advanced Features

  • ๐Ÿ”น Prefetching: Preload resources in the background.
  • ๐Ÿ”น Request Deduplication: Automatically combines identical concurrent requests.
  • ๐Ÿ”น Interceptors: Middleware to modify requests/responses on the fly.
  • ๐Ÿ”น Retry with Backoff: Retries failed requests with exponential delay.
  • ๐Ÿ”น Persistent Cache: Uses localStorage to keep cache across sessions.
  • ๐Ÿ”น Abortable Requests: Easily cancel unnecessary requests.
  • ๐Ÿ”น React Hooks: Built-in hooks to integrate with modern React apps.

๐Ÿง What Makes Fetchless Unique

  • ๐Ÿ›ก๏ธ Best practices by default: timeouts, error handling, cache control.
  • ๐Ÿงฌ Network-aware logic: smart cache modes, deduplication, aborts.
  • โšก Full TypeScript + React support.
  • ๐Ÿ“ฆ Smart caching: avoid redundant calls, even between sessions.
  • โ†บ Automatic retries when the network fails.

๐Ÿงช Code Examples

โœจ Basic Usage

import { get } from 'fetchless';

get('https://api.example.com/data')
  .then(response => console.log(response.data));
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”ง Creating a Custom Client

import { createAdvancedClient } from 'fetchless';

const client = createAdvancedClient({
  persistCache: true,
  dedupeRequests: true,
  retryOptions: {
    maxRetries: 3,
    backoffFactor: 300,
    retryStatusCodes: [408, 429, 500, 502, 503, 504]
  }
});
Enter fullscreen mode Exit fullscreen mode

โœ๏ธ Using Interceptors

client.addRequestInterceptor((url, config) => [
  url,
  {
    ...config,
    headers: {
      ...config?.headers,
      'Authorization': `Bearer ${getToken()}`
    }
  }
]);

client.addResponseInterceptor((response) => ({
  ...response,
  data: transformData(response.data)
}));
Enter fullscreen mode Exit fullscreen mode

โŒ› Prefetching

import { prefetch } from 'fetchless';

prefetch('https://api.example.com/future-data');
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”„ Abortable Requests

import { abortableGet } from 'fetchless';

const { promise, abort } = abortableGet('https://api.example.com/large-data');

promise.then(response => console.log(response.data));
abort();
Enter fullscreen mode Exit fullscreen mode

๐Ÿš€ React Integration

import { useFetchless } from 'fetchless';

function UserProfile({ userId }) {
  const { data, loading, error } = useFetchless(`https://api.example.com/users/${userId}`);

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <div>
      <h1>{data.name}</h1>
      <p>{data.email}</p>
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“Š Cache Statistics

import { defaultClient } from 'fetchless';

const stats = defaultClient.getStats();
console.log(stats);
// { hits: 5, misses: 2, ratio: 0.71, size: 7 }

defaultClient.clearCache();
Enter fullscreen mode Exit fullscreen mode

๐ŸŒ Learn More


โœจ Installation

npm install fetchless
Enter fullscreen mode Exit fullscreen mode

๐Ÿ™‹ Call to Action

Try Fetchless today.
Open an issue.
Star the project.
And never write raw fetch again โค๏ธ.


๐Ÿ”– DEV.to Tags

#javascript #typescript #webdev #react #fetchless #opensource
Enter fullscreen mode Exit fullscreen mode

Top comments (0)