Skip to content

Latest commit

 

History

History
158 lines (127 loc) · 6.88 KB

File metadata and controls

158 lines (127 loc) · 6.88 KB
layout home
title openFetch — fetch-native HTTP client
titleTemplate false
description Fetch-native HTTP client with interceptors, middleware, Standard Schema JSON, retry lifecycle hooks, memory cache, and Ky-style ergonomics — Node 18+, edge, browsers. No XHR.
head
meta
property content
og:type
website
meta
meta
property content
og:locale
en_US
meta
property content
og:title
openFetch — fetch-native HTTP client
meta
property content
og:description
Interceptors, middleware, Standard Schema JSON, retry hooks, memory cache on fetch — Node 18+, edge, browsers. No XHR.
meta
name content
twitter:title
openFetch — fetch-native HTTP client
meta
name content
twitter:description
Standard Schema JSON, retry lifecycle hooks, interceptors, middleware, cache on fetch. Node 18+, edge — no XHR.
hero
name text tagline actions
openFetch
HTTP 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.
theme text link
brand
Get started
/getting-started
theme text link
alt
GitHub
features
title details
Fetch-only transport
One code path on top of standard fetch — Node, Bun, Deno, Workers, and modern browsers without mandatory polyfills.
title details
Interceptors & middleware
Request/response interceptors plus composable middleware for auth, logging, retries, and caching in a predictable order.
title details
Retry & in-memory cache
Optional retry with backoff and GET/HEAD memory cache with TTL / SWR-style patterns when you opt in.
title details
Structured errors & safety hooks
OpenFetchError with stable codes, optional URL guard for untrusted URLs, and helpers for safe logging.
title details
Tree-shakable entrypoints
Import the core client or add plugins and the fluent sugar API from dedicated subpaths.
title details
Server components friendly
No window assumption — suitable for SSR, APIs, and React Server Components patterns.
title details
Schema validation & Ky-style ergonomics
Optional Standard Schema on JSON, throwHttpErrors, native Request input, sync init hooks, retry onAfterResponse / OpenFetchForceRetry — see Features & pipeline.

At a glance

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:

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:

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:

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)

Export Role
default Pre-built createClient() instance
createClient / create New client with optional initialDefaults
createFluentClient Callable fluent URL chains (from /sugar)
retry, timeout, hooks, debug, strictFetch Middleware plugins (from /plugins)
OpenFetchError, isOpenFetchError, isHTTPError, isTimeoutError Typed errors + guards
SchemaValidationError, isSchemaValidationError Standard Schema failures on JSON
OpenFetchForceRetry, isOpenFetchForceRetry Force another retry attempt from onAfterResponse
Standard Schema types StandardSchemaV1, StandardSchemaV1InferOutput, …
InterceptorManager Low-level interceptor stack
createRetryMiddleware Retry middleware factory
MemoryCacheStore, createCacheMiddleware, appendCacheKeyVaryHeaders In-memory cache
maskHeaderValues, cloneResponse, idempotency helpers Logging and retry ergonomics
Types OpenFetchConfig, OpenFetchResponse, Middleware, OpenFetchClient, etc.
assertSafeHttpUrl Optional 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.