ofetch is a fetch wrapper library that works on Node.js, browsers, and workers.
The tool addresses the inconsistencies and limitations of the native fetch API across different JavaScript environments. It provides automatic JSON parsing for responses, intelligently detecting content types and returning Blob objects for binary data. When sending requests with object bodies, ofetch automatically serializes them to JSON and sets appropriate headers. The library includes built-in error handling that throws exceptions when response status indicates failure, with parsed error bodies available for inspection. It implements automatic retry logic for transient failures like timeouts and rate-limiting, with configurable retry counts and delays, though it avoids retrying mutating requests by default to prevent side effects. Additional conveniences include request timeouts, base URL handling with proper slash normalization, query parameter management, and TypeScript support for response type assistance.
Developers should choose ofetch when they want a more ergonomic fetch experience without the boilerplate of manual JSON handling, error checking, and retry logic. It suits projects targeting multiple JavaScript runtimes that need consistent behavior across Node.js, browsers, and workers. The library is particularly valuable for API clients where automatic retries on transient errors and sensible defaults reduce implementation complexity.
The project maintains active development with regular commits addressing bug fixes and feature refinements. The codebase shows attention to edge cases, such as handling streaming bodies and ensuring proper header defaults for different request methods. The maintainers respond to issues and incorporate community feedback into the tool's evolution. Development includes comprehensive handling of various response types and careful consideration of when to apply automatic behaviors versus when to require explicit configuration.