ofetch is a small HTTP client built on fetch with JSON helpers, retries, timeouts, interceptors, and typed responses. It runs on Node, browsers, and worker runtimes with optional proxy configuration.
Overview
ofetch wraps the standard fetch API with ergonomic defaults for JSON APIs. It parses JSON automatically, stringifies object bodies for POST-like verbs, sets sensible content-type headers, and throws rich errors when response.ok is false.
Retry logic covers specific status codes such as 408, 429, and 5xx gateways, with configurable counts and delays. Timeouts abort hung requests, and ofetch.create builds clients with shared baseURL, headers, and interceptors.
Hooks run at request, response, and error stages for logging or auth injection. ofetch.raw exposes headers for advanced cases, while ofetch.native passes through to the environment fetch implementation.
Proxy support documents Node undici ProxyAgent usage, environment variables on Bun and Deno, and optional TypeScript augmentation of FetchOptions for custom fields.
Key features
- JSON body parse and stringify
- Automatic retry on selected statuses
- Request and response interceptors
- baseURL and query helpers via ufo
- Typed response generics
- Streaming and binary body support
- Proxy and SSE examples
Use cases
- Typed API calls in Nuxt and UnJS stacks
- Shared HTTP client defaults in services
- Lightweight fetch wrapper in workers