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.
Official sources
- [1]ofetch stable v1 README(2026-10-05)
- [2]ofetch v1.5.1 release(2026-10-05)
- [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
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
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
Run the request with Node.js
Confirm that ofetch retrieves the response and returns the parsed JSON object.
node demo.mjs
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
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- Ky17,104 Stars
6 shared tag(s) · 1 shared category(s) · Same language
extend Fetch API with concise retries, timeouts, hooks, and JSON handling
TypeScript - Superstruct7,127 Stars
5 shared tag(s) · 1 shared category(s) · Same language
compose small structs to validate JavaScript and TypeScript data at runtime
TypeScript - io-ts6,814 Stars
5 shared tag(s) · 1 shared category(s) · Same language
decode and encode unknown values with codecs while inferring TypeScript types from the same definitions
TypeScript - Runtypes2,699 Stars
5 shared tag(s) · 1 shared category(s) · Same language
validate unknown values with composable runtime types and infer TypeScript types from the same definitions
TypeScript - Ajv14,850 Stars
4 shared tag(s) · 1 shared category(s) · Same language
compile JSON Schema or JTD contracts into fast runtime validators for API and configuration data
TypeScript - openapi-typescript8,391 Stars
4 shared tag(s) · 1 shared category(s) · Same language
generate runtime-free TypeScript types from OpenAPI 3.0 and 3.1 contracts
TypeScript
Report incorrect information
Tell us if any listing information is incorrect or outdated.