PACKAGE · HTTP CLIENT

ofetch

A better fetch API. Works on node, browser and workers.

WEEKLY DOWNLOADS 28.2M
STARS 5.4K
FORKS 212
OPEN ISSUES 153
GZIP SIZE 37.3 kB
UNPACKED SIZE 63.9 kB
DEPENDENCIES 4
LAST UPDATED 1y ago
DOWNLOAD TRENDS

ofetch downloads · last 12 months

Download trends for ofetch1 download series from Nov 2025 to Oct 2026. Use left and right arrow keys to inspect monthly values.032.4M64.9M97.3M129.8MNov 2025FebMayAugOct 2026
ofetch
ABOUT OFETCH

ofetch is an HTTP client that provides a higher-level API around fetch for making requests in Node.js, browsers, and workers. It addresses the repeated work of issuing requests and handling responses with a consistent interface across those environments.

Its design centers on making fetch easier to use without limiting it to a single JavaScript runtime. The package is suited to developers who want a shared request pattern across client-side code, server-side code, and worker workflows, while retaining fetch as the underlying mental model.

The primary entry point is $fetch, which can be used to make requests and return parsed response data. The ofetch API also supports creating a configured client with create, so shared request options can be applied across calls; hooks provide points to customize request and response handling, and retry and timeout options cover common request behavior.

Because ofetch works in Node.js, browsers, and workers, the same client pattern can fit frontend applications, server routes, and background tasks. It can be integrated wherever those runtimes can make HTTP requests, including code that needs shared defaults or centralized request and response handling rather than repeated per-call setup.

The package is MIT-licensed and is listed at version 1.5.1, with 10.7M weekly downloads and 5.4K GitHub stars. Its reported unpacked size is 63.9 kB and gzip bundle size is 37.3 kB; these figures are useful when evaluating whether its API conveniences fit a bundle budget, but do not by themselves describe application-level performance.

ofetch remains an HTTP client, not a complete data-fetching or caching layer, so applications may need to supply their own higher-level policies. Its cross-runtime behavior does not remove the need to account for differences in available runtime APIs, and teams should verify the request, retry, and error-handling behavior they require before adopting it.

WHEN TO USE
  • Use $fetch when you want a concise call that returns parsed response data instead of repeating fetch response parsing at each call site.
  • Use create to define a client with shared base options for requests to the same service, keeping common configuration out of individual calls.
  • Use ofetch when the same HTTP request pattern needs to run in Node.js, browsers, and workers.
  • Use request and response hooks to centralize behavior that should apply consistently across calls, such as handling request or response events.
  • Use the retry and timeout options when individual request calls need explicit retry or time-limit behavior.
  • Use ofetch in frontend, server-route, or worker code where a fetch-based API is preferable to maintaining separate client patterns for each runtime.
WHEN NOT TO USE
  • Avoid ofetch if you require a complete application data-fetching layer with caching or coordinated background updates; use fetch directly and implement those policies separately.
  • Avoid it if your code must expose the native fetch Response object unchanged; use fetch directly so response handling remains under your control.
  • Avoid it if your target runtime does not provide the APIs required by the package; use a client compatible with that runtime or provide an appropriate runtime implementation.
  • Avoid it if the reported 37.3 kB gzip bundle size exceeds your bundle budget; use the native fetch API to avoid adding this package to the bundle.
  • Avoid it if your project requires request behavior that cannot be expressed with ofetch's options, hooks, retry, or timeout patterns; use fetch directly and implement the required behavior explicitly.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

COMPARISONS 6
ofetch vs ky ★ 17.2K · 10.1M/wk ofetch vs node-fetch ★ 8.8K · 298.7M/wk ofetch vs superagent ★ 16.6K · 33.4M/wk ofetch vs got ★ 15.0K · 52.8M/wk ofetch vs undici ★ 7.8K · 347.4M/wk ofetch vs axios ★ 109.5K · 146.3M/wk