Skip to main content
The Fetch client is built on the native Fetch API and works in all modern browsers and Node.js environments. It’s the default client for OpenAPI TypeScript with zero dependencies.

Installation

The Fetch client is included in the main @hey-api/openapi-ts package. To use it standalone:

Basic Usage

1

Create a client instance

2

Make API calls

3

Handle responses

Configuration

The Fetch client supports comprehensive configuration options:

Client Options

Runtime Configuration

Update client configuration after creation:

HTTP Methods

The client provides methods for all HTTP verbs:

Authentication

The Fetch client supports multiple authentication schemes:

Bearer Token

Basic Authentication

API Key

Interceptors

Add request, response, and error interceptors:

Request Interceptor

Response Interceptor

Error Interceptor

Response Parsing

Control how responses are parsed:

Auto (Default)

JSON

Text

Blob

Stream

Server-Sent Events

Stream real-time data with Server-Sent Events:

Body Serialization

Customize how request bodies are serialized:

JSON (Default)

FormData

URL Encoded

Query Serialization

Customize query parameter serialization:

Advanced Examples

Custom Fetch Implementation

Request Cancellation

Response Validation

Response Transformation

TypeScript Types

Import client types for advanced usage:

Next Steps

Axios Client

Advanced features with Axios

Authentication

Set up API authentication

Interceptors

Add request/response interceptors

Error Handling

Handle errors effectively