The ofetch client wraps the popular ofetch library, providing a universal fetch wrapper that works in browsers and Node.js with advanced features like retry, interceptors, and native Node.js optimizations.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/hey-api/openapi-ts/llms.txt
Use this file to discover all available pages before exploring further.
Installation
ofetch is a peer dependency and must be installed separately.
Basic Usage
Configuration
The ofetch client extends ofetch configuration with OpenAPI TypeScript features:Client Options
Custom ofetch Instance
Use an existing ofetch instance:HTTP Methods
- GET
- POST
- PUT
- PATCH
- DELETE
Response Styles
Fields Style (Default)
Data Style
ofetch Hooks
Use ofetch’s powerful hook system:onRequest Hook
onRequestError Hook
onResponse Hook
onResponseError Hook
Retry Configuration
Default Retry
Exponential Backoff
Per-Request Retry
Authentication
Bearer Token
API Key
Interceptors
Add request, response, and error interceptors:Request Interceptor
Response Interceptor
Error Interceptor
Server-Sent Events
Stream real-time data:Node.js Features
HTTP/HTTPS Agent
Custom Dispatcher (Node.js 18+)
Proxy Support
Response Parsing
Auto (Default)
Custom Parser
Specific Format
Request Cancellation
Advanced Examples
Rate Limiting with Retry
Circuit Breaker Pattern
Request Queue
TypeScript Types
Comparison with Fetch Client
| Feature | ofetch Client | Fetch Client |
|---|---|---|
| Dependencies | Requires ofetch | Zero dependencies |
| Browser Support | Modern browsers | Modern browsers |
| Node.js Support | Optimized | Basic |
| Retry Support | Built-in | Manual |
| Hooks | ofetch hooks | Interceptors only |
| Bundle Size | ~3KB | ~2KB |
Next Steps
Fetch Client
Zero-dependency alternative
Ky Client
Alternative with retry support
Retry Configuration
Configure automatic retries
Node.js Features
Use Node.js optimizations