What is ofetch?
ofetch is a modern HTTP client that provides a better fetch API experience. It works seamlessly across Node.js, browser, and worker environments with intelligent defaults and powerful features that make HTTP requests simpler and more reliable.Key features
ofetch enhances the standard fetch API with features designed for modern development:- Smart JSON handling - Automatically parses JSON responses and stringifies request bodies
- Auto retry - Automatically retries failed requests with configurable status codes
- Better errors - Throws friendly error messages with compact stack traces and parsed error bodies
- Type safety - Full TypeScript support with response type inference
- Interceptors - Lifecycle hooks for requests and responses
- Timeout support - Built-in timeout with automatic abort
- Query params - Easy query string management with the
queryoption - Base URL - Set base URLs for cleaner request paths
- Proxy support - Works with HTTP proxies in Node.js, Bun, and Deno
- SSE streaming - Handle server-sent events with response streams
Get started
Quickstart
Get up and running with ofetch in minutes
Installation
Install ofetch in your project
Why ofetch?
The standard fetch API is powerful but requires boilerplate for common tasks. ofetch eliminates that friction:- Parses JSON responses
- Stringifies request bodies
- Sets appropriate headers
- Throws errors for failed requests
- Retries on network failures