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
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()
transformRequest / transformResponse Ordered arrays on config Built-in transform pipeline Hooks (no config arrays)
Validated JSON (Standard Schema) jsonSchema + fluent .json(schema) Bring your own (e.g. Zod in transform) .json(schema)
HTTP status gate validateStatus + throwHttpErrors validateStatus throwHttpErrors
Native Request + sync init request(Request) + init[] Config-based (no first-class init[]) Request + init hooks
Retry with backoff (opt-in) Plugins + onAfterResponse / ForceRetry Separate Retry + afterResponse hook
GET memory cache (TTL / SWR) createCacheMiddleware + store Third-party / DIY
Uniform client response OpenFetchResponse AxiosResponse Response / parsed
Errors, safe logs, URL guard toShape, redact URL, mask headers, URL guard AxiosError; DIY redaction Typed errors; DIY redaction
Timeout vs user cancel ERR_TIMEOUT vs ERR_CANCELED Often AbortError for both TimeoutError vs AbortError
Fluent client + memo createFluentClient + .memo() Native chaining (no bundled memo)
POST retry idempotency key Opt-in auto header (retry plugin) Manual / interceptors Manual
Edge & RSC friendly Uses fetch Adapters 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. 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. Features & request pipeline — full feature list, merge → dispatch diagrams, retry hooks
  6. Plugins & fluent API@hamdymohamedak/openfetch/plugins, @hamdymohamedak/openfetch/sugar
  7. Interceptors & middleware — execution order, dispatch internals, use(), custom middleware
  8. Retry & cache — retry budgets, idempotency, createCacheMiddleware, TTL / SWR
  9. Errors & securityOpenFetchError, codes, guards, safe logging, assertSafeHttpUrl
  10. 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