OSS TanbouSign in with GitHub

add JSON parsing, retries, timeouts, and interceptors to fetch across Node, browsers, and workers

About these scores

OSS scale score is an unbounded metric that log-compresses and weights Stars, Watchers, Forks, and Contributors. Discovery score is the current OSS scale score minus the score at discovery. Update pace is commits in the last 30 days, growth momentum is the OSS scale score difference within the recent observation window, and OSS health is a 0–100 rating based on available recency, Community Health, and release data.

Stars
5,360
Primary language
TypeScript
License
MIT
Repository last updated
Oct 4, 2026
On this page

Overview

ofetch is an HTTP client built on Fetch APIs for Node.js, browsers, and workers. It adds automatic JSON parsing, JSON request bodies, non-2xx errors, retries, timeouts, base URLs, query parameters, and interceptors behind one API.

Features and best fit

Based on official documentation; not hands-on tested · Content checked:

Key features

Parse JSON and binary responses according to the requested type

Stable v1 parses JSON and native values with destr, uses Blob for binary content, and supports explicit response types such as text, blob, arrayBuffer, and stream.

Sources: [1]

Simplify JSON request bodies and HTTP error handling

Objects passed as a request body are JSON-stringified, and POST, PUT, and PATCH requests receive JSON headers by default. Non-2xx responses are exposed as FetchError with parsed error data available on error.data.

Sources: [1]

Share retry, timeout, baseURL, and interceptor behavior

Options cover retries, delays, timeouts, base URLs, and query parameters, while request and response interceptors centralize cross-cutting behavior. ofetch.create can produce a client with shared defaults.

Sources: [1]

Best fit

Fits universal applications that share one fetch wrapper across runtimes

It is useful when frontend, SSR, Node.js, and worker code should use a common HTTP abstraction rather than maintaining separate clients per runtime.

Sources: [1]

Before adoption

Decide retry behavior carefully for requests with side effects

Stable v1 avoids retries by default for POST, PUT, PATCH, and DELETE to reduce side-effect risk. Setting a custom retry count can enable retries for those methods, so API idempotency should be reviewed explicitly.

Sources: [1]

Do not mix stable 1.5.1 documentation with the v2 alpha development line

The repository main branch tracks v2 alpha development, which differs from stable 1.x documentation and package metadata. Evaluate stable 1.5.1 using the v1 docs and its release notes; 1.5.1 fixes header normalization after the onRequest hook.

Sources: [1][2]

Official sources

  1. [1]ofetch stable v1 README(2026-10-05)
  2. [2]ofetch v1.5.1 release(2026-10-05)
  3. [3]ofetch MIT license on stable v1(2026-10-05)
Supplemental curator note

Pin the 1.x line when you need the stable API. The current main branch is the v2 alpha development line, so use the stable v1 documentation when evaluating 1.5.1. That patch fixes header normalization after the onRequest hook.

Try it in 3 steps

  1. 1

    Install stable ofetch 1.5.1 in an isolated project

    Pin the stable 1.x release explicitly instead of using the v2 alpha development line.

    demo=$(mktemp -d "${TMPDIR:-/tmp}/ofetch.XXXXXX") && cd "$demo" && npm init -y >/dev/null && npm install --save-exact ofetch@1.5.1
  2. 2

    Create a local HTTP server and request it with ofetch

    Use a local server so the check exercises the documented automatic JSON parsing without depending on an external service.

    printf "%s\n" "import {createServer} from 'node:http';" "import {ofetch} from 'ofetch';" "const server = createServer((request, response) => { response.setHeader('content-type', 'application/json'); response.end(JSON.stringify({ok: true})); });" "server.listen(0, '127.0.0.1', async () => {" " const address = server.address();" " try {" " const data = await ofetch('http://127.0.0.1:' + address.port + '/');" " if (data.ok !== true) process.exitCode = 1;" " console.log(data);" " } finally { server.close(); }" "});" > demo.mjs
  3. 3

    Run the request with Node.js

    Confirm that ofetch retrieves the response and returns the parsed JSON object.

    node demo.mjs
Check the official README

Growth

Growth trends · Last 30 days

5,360 Stars

Trend data is still being collected.

Development activity

Last 90 days · weekly

Commits (last 30 days)
0
Open PRs
78

Development activity is still being collected.

Built with

Categories and tags

Categories

GitHub data

GitHub dataView detailed GitHub data
Stars
5,360
Forks
197
Watchers
14
Open issues
52
Contributors
65
Owner type
Organization
Primary language
TypeScript
License
MIT
Repository last updated
Oct 4, 2026
Write a related article

Share a guide or use case for this OSS in Markdown. Articles are published after administrator approval.

Report incorrect information

Tell us if any listing information is incorrect or outdated.

After reading this page, do you know what to do next?