Skip to main content
Create a custom HTTP client adapter to integrate any HTTP library with OpenAPI TypeScript. This guide shows you how to build adapters for popular libraries or create completely custom implementations.

Overview

A custom client adapter must implement the Client interface from @hey-api/client-core, which provides:
  • HTTP method functions (GET, POST, PUT, PATCH, DELETE, etc.)
  • Request/response configuration
  • Authentication support
  • Body and query serialization
  • Type safety

Installation

Install the custom client package:

Basic Structure

A custom client implements the core client interface:

Example: Axios Adapter

Here’s a complete example of an Axios adapter:

Example: Superagent Adapter

Adapter for the SuperAgent library:

Helper Functions

The @hey-api/custom-client package provides helper functions:

buildClientParams

Build URL with path and query parameters:

Body Serializers

Pre-built body serializers:

Authentication

Implement authentication support:

Query Serialization

Implement custom query serialization:

TypeScript Types

Define proper TypeScript types for your adapter:

Testing Your Adapter

Test your custom adapter:

Publishing Your Adapter

To share your adapter with others:
1

Create package.json

2

Build and test

3

Publish to npm

Best Practices

Always return both data and error fields:
Implement all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS).
Use proper TypeScript types throughout your implementation:
Provide clear documentation for all configuration options and their defaults.

Next Steps

Fetch Client

Reference implementation

Axios Client

Another adapter example

Client Core

Core client types and utilities

Authentication

Implement authentication