Skip to content

openFetchHTTP that feels native to fetch

Interceptors, middleware, Standard Schema JSON, retry lifecycle hooks, and memory cache — fetch-only for Node 18+, the edge, and modern browsers.

TS

Open in your assistant

Pre-fills a prompt that points at the docs site and . If the message box is empty, paste the prompt from the address bar or type it manually — URL prefill behavior depends on the product.

At a glance

CapabilityopenFetchAxiosky
TransportopenFetchfetchAxiosXHR (default in browsers)kyfetch
Runtime depsopenFetchZeroAxiosOwn stackkyZero
Node H2 / fetch dispatcheropenFetch Opt-in: user `undici`; `dispatcher` / `allowH2`AxiosNode adaptersky Opt-in: user `undici` (docs)
Instance & defaultsopenFetch createClientAxios axios.createky ky.create
Request / response interceptorsopenFetch BothAxios Bothky Hooks only
Composable middlewareopenFetch use()Axiosky
transformRequest / transformResponseopenFetch Ordered arrays on configAxios Built-in transform pipelineky Hooks (no config arrays)
Validated JSON (Standard Schema)openFetch jsonSchema + fluent .json(schema)Axios Bring your own (e.g. Zod in transform)ky .json(schema)
HTTP status gateopenFetch validateStatus + throwHttpErrorsAxios validateStatusky throwHttpErrors
Native Request + sync initopenFetch request(Request) + init[]Axios Config-based (no first-class init[])ky Request + init hooks
Retry with backoff (opt-in)openFetch Plugins + onAfterResponse / ForceRetryAxios Separateky Retry + afterResponse hook
GET memory cache (TTL / SWR)openFetch createCacheMiddleware + storeAxios Third-party / DIYky
Uniform client responseopenFetch OpenFetchResponseAxios AxiosResponseky Response / parsed
Errors, safe logs, URL guardopenFetch toShape, redact URL, mask headers, URL guardAxios AxiosError; DIY redactionky Typed errors; DIY redaction
Timeout vs user cancelopenFetch ERR_TIMEOUT vs ERR_CANCELEDAxios Often AbortError for bothky TimeoutError vs AbortError
Fluent client + memoopenFetch createFluentClient + .memo()Axiosky Native chaining (no bundled memo)
POST retry idempotency keyopenFetch Opt-in auto header (retry plugin)Axios Manual / interceptorsky Manual
Edge & RSC friendlyopenFetch Uses fetchAxios Adaptersky fetch

Bundle size depends on your toolchain and imports. openFetch layers practical fetch ergonomics: Standard Schema JSON, status gates, Request + sync init, retry lifecycle hooks, ERR_TIMEOUT vs cancel — see Features & pipeline for the full diagram.

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. Visual guide (hands-on) — animated request flow + practical examples for every major feature
  2. Getting started — install, default export, createClient, first requests
  3. HTTP methods — GET, POST, PUT, PATCH, DELETE, request(), bodies and query params
  4. React & Vue — hooks, composables, shared clients, RSC notes
  5. Configuration — full request config, rawResponse, merge rules, helper exports
  6. Features & request pipeline — full feature list, merge → dispatch diagrams, retry hooks
  7. Plugins & fluent API@hamdymohamedak/openfetch/plugins, @hamdymohamedak/openfetch/sugar
  8. Interceptors & middleware — execution order, dispatch internals, use(), custom middleware
  9. Retry & cache — retry budgets, idempotency, createCacheMiddleware, TTL / SWR
  10. Errors & securityOpenFetchError, codes, guards, safe logging, assertSafeHttpUrl
  11. AI assistants & skills — concise API guidance for models; SKILL.md skill bundle and skills.sh / Agent Skills format

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, isOpenFetchError, isHTTPError, isTimeoutErrorTyped errors + guards
SchemaValidationError, isSchemaValidationErrorStandard Schema failures on JSON
OpenFetchForceRetry, isOpenFetchForceRetryForce another retry attempt from onAfterResponse
Standard Schema typesStandardSchemaV1, StandardSchemaV1InferOutput, …
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