Skip to content

openFetchHTTP client for the fetch era

Interceptors, middleware, retry, and memory cache — zero hard dependency on XHR, built for Node 18+, browsers, and the edge.

At a glance

CapabilityopenFetchThis libraryAxiosky
TransportfetchXHR (default in browsers)fetch
Runtime depsZeroOwn stackZero
Instance & defaults createClient axios.create ky.create
Request / response interceptors Both Both Hooks only
Composable middleware use()
Retry & memory cache (opt-in) Plugins Separate Retry only
Uniform client response OpenFetchResponse AxiosResponse Response / parsed
Edge & RSC friendly Uses fetch Adapters fetch

Bundle size depends on your toolchain and imports. The core idea: openFetch layers ergonomics on native fetch without switching transports.

Same request — three HTTP clients

The EscuelaJS categories API returns a JSON array. Below: openFetch, Axios, and ky.

openFetch — shared defaults, structured response, and room for interceptors/middleware:

ts
import openFetch from "@hamdymohamedak/openfetch";

const res = await openFetch.get(
  "https://api.escuelajs.co/api/v1/categories"
);
// res.data, res.status, res.headers, res.config

Axios — familiar API; different transport defaults in the browser:

ts
import axios from "axios";

const res = await axios.get(
  "https://api.escuelajs.co/api/v1/categories"
);
// res.data, res.status, res.headers, res.config

ky — minimal API on top of fetch:

ts
import ky from "ky";

const data = await ky
  .get("https://api.escuelajs.co/api/v1/categories")
  .json();

Why developers reach for a client layer

  • Shared configurationbaseURL, headers, timeouts, and unwrapResponse once per createClient instance.
  • Cross-cutting behavior — attach auth, tracing, feature flags, and error normalization via interceptors and middleware.
  • Resilience — retry policies and caching strategies without rewriting every call site.
  • Predictable errors — map HTTP and network failures to typed errors instead of ad-hoc try/catch parsing.

openFetch targets teams that want those benefits while staying on fetch everywhere the platform already provides it.

Documentation

  1. Getting started — install, default export, createClient, first requests
  2. HTTP methods — GET, POST, PUT, PATCH, DELETE, request(), bodies and query params
  3. React & Vue — hooks, composables, shared clients, RSC notes
  4. Configuration — full request config, rawResponse, merge rules, helper exports
  5. Plugins & fluent API@hamdymohamedak/openfetch/plugins, @hamdymohamedak/openfetch/sugar
  6. Interceptors & middleware — execution order, dispatch internals, use(), custom middleware
  7. Retry & cache — retry budgets, idempotency, createCacheMiddleware, TTL / SWR
  8. Errors & securityOpenFetchError, codes, safe logging, assertSafeHttpUrl

Public API (summary)

ExportRole
defaultPre-built createClient() instance
createClient / createNew client with optional initialDefaults
createFluentClientCallable fluent URL chains (from /sugar)
retry, timeout, hooks, debug, strictFetchMiddleware plugins (from /plugins)
OpenFetchError, isOpenFetchErrorTyped errors + type guard
InterceptorManagerLow-level interceptor stack
createRetryMiddlewareRetry middleware factory
MemoryCacheStore, createCacheMiddleware, appendCacheKeyVaryHeadersIn-memory cache
maskHeaderValues, cloneResponse, idempotency helpersLogging and retry ergonomics
TypesOpenFetchConfig, OpenFetchResponse, Middleware, OpenFetchClient, etc.
assertSafeHttpUrlOptional SSRF-style guard for literal IP/localhost in URLs

Requirements

Node.js 18+ or any runtime with fetch and AbortController.

Source & package

Other languages

Browse all translations.

MIT · @hamdymohamedak/openfetch