# ofetch

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

Source: https://talira.ai/catalog/ofetch-brxwg7d2
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library
- Categories: [libraries / http clients](https://talira.ai/categories/libraries/http-clients), [languages / javascript](https://talira.ai/categories/languages/javascript)
- Licence: MIT[^1]
- Pricing: Free and open source[^1]
- Free tier: yes[^1]
- Self-hostable: yes[^2]
- API: yes[^2]
- Backed by: [UnJS](https://talira.ai/orgs/unjs.md)

ofetch is a thin layer over the Fetch API from the UnJS project that runs in Node.js, browsers and worker runtimes. It parses JSON responses on its own (and returns a Blob for binary content types), stringifies object bodies and sets JSON headers, throws a `FetchError` with the parsed error body when a response isn't ok, and retries idempotent requests on status codes such as 429, 500 and 503. It adds timeouts, a `baseURL`, query parameters, typed responses and async interceptors (`onRequest`, `onResponse` and their error variants), with `ofetch.create` for shared defaults and `ofetch.raw` for the full response. The stable release is 1.x; a 2.0 alpha is being developed on the main branch.

## Links

- Website: https://unjs.io/packages/ofetch
- GitHub: https://github.com/unjs/ofetch

## Problems it solves

- one fetch helper that works the same in Node.js, the browser and edge workers
- stop writing response.json() and JSON.stringify for every API call
- get the server's error response body when a request fails, not just the status code
- retry GET requests on 429 and 5xx responses without retrying POSTs and creating duplicates
- log or add auth headers to every request with interceptors around fetch
- set a base URL and query parameters for API calls without building URLs by hand
- abort an API request after a few seconds if the server doesn't answer

## Features

- automatic JSON parsing, Blob for binary content types
- automatic JSON body stringifying and headers
- FetchError with the parsed error body
- retries on configurable status codes, not by default for POST, PUT, PATCH and DELETE
- timeout option
- baseURL and query options
- typed responses
- onRequest, onRequestError, onResponse and onResponseError interceptors
- ofetch.create for shared defaults
- ofetch.raw for headers and the full response
- streaming bodies and SSE
- proxies through undici's ProxyAgent in Node.js

## Capabilities

- Has an API: plan not known

## Trust

Overall: 0.32 out of 1.
Signals: backing 0.30, extensibility 0.20.

- backed by UnJS

Warnings:

- GitHub activity not fetched yet

## Alternatives

- [node-fetch](https://talira.ai/catalog/node-fetch-f6wxdep8.md): A light-weight module that brings the Fetch API to Node.js
- [axios](https://talira.ai/catalog/axios-0sg488rd.md): Promise based HTTP client for the browser and node.js
- [SuperAgent](https://talira.ai/catalog/superagent-b9qa7pyb.md): Ajax for Node.js and browsers (JS HTTP client)
- [Ky](https://talira.ai/catalog/ky-7jhb33p5.md): Tiny & elegant JavaScript HTTP client based on the Fetch API
- [undici](https://talira.ai/catalog/undici-kmdjat1w.md): An HTTP/1.1 client, written from scratch for Node.js
- [Got](https://talira.ai/catalog/got-0csab4w7.md): Human-friendly and powerful HTTP request library for Node.js

## Sources

[^1]: https://github.com/unjs/ofetch/blob/main/LICENSE (checked 20 Nov 2026)
[^2]: https://github.com/unjs/ofetch (checked 20 Nov 2026)
