Skip to main content
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.

Installation

ofetch is a peer dependency and must be installed separately.

Basic Usage

1

Create a client instance

2

Make API calls

Configuration

The ofetch client extends ofetch configuration with OpenAPI TypeScript features:

Client Options

Custom ofetch Instance

Use an existing ofetch instance:

HTTP Methods

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

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