Skip to main content
CallApi is a modern fetch wrapper designed to solve real problems. Here’s how it compares to other popular libraries in the ecosystem.

Philosophy

CallApi is built on four core principles: Lightweight: Small bundle size (under 6KB). Zero dependencies. Pure ESM. Simple: Based on the Fetch API and mirrors its interface 1-to-1. Only adds useful features with sensible defaults. Type-safe: Built with TypeScript. Full type support for responses and errors via schemas, validators, and manual generics. Extensible: Plugins and hooks let you add or modify features without changing the core code.

CallApi vs Axios

Overview

Axios has been a fundamental part of web development for years and remains popular. However, modern web development has evolved, and CallApi addresses many of Axios’s limitations.

Key Differences

Axios:
  • Based on XMLHttpRequest (legacy API)
  • Custom API design
  • Verbose configuration for some use cases
  • Requires adapters for different environments
CallApi:
  • Based on modern Fetch API
  • Drop-in replacement for fetch
  • Concise, intuitive API
  • Works everywhere (browsers, Node 18+, Deno, Bun, Workers)

Migration Example

import axios from 'axios';

const api = axios.create({
  baseURL: 'https://api.example.com',
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json',
  },
});

// Add auth token
api.interceptors.request.use((config) => {
  config.headers.Authorization = `Bearer ${getToken()}`;
  return config;
});

// Handle errors
api.interceptors.response.use(
  (response) => response,
  (error) => {
    if (error.response?.status === 401) {
      redirectToLogin();
    }
    return Promise.reject(error);
  }
);

try {
  const response = await api.get('/users');
  const users = response.data;
} catch (error) {
  if (axios.isAxiosError(error)) {
    console.error(error.response?.data);
  }
}

When to Choose Axios

  • You need IE11 support
  • Your team is deeply familiar with Axios and migration cost is high
  • You rely on Axios-specific ecosystem packages

When to Choose CallApi

  • You want modern, fetch-based API
  • Bundle size matters
  • You need TypeScript type inference
  • You want built-in retries and deduplication
  • You need schema validation
  • You’re starting a new project

CallApi vs Ky

Overview

Ky is a popular modern fetch wrapper with a focus on simplicity and developer experience.

Key Differences

FeatureKyCallApi
Fetch-based
Timeout Support
Retry Logic✅ (More flexible)
Hooks✅ (More comprehensive)
JSON Handling✅ (Content-Type aware)
Bundle Size~5KB<6KB

When to Choose Ky

  • You want a minimal API with no extra features
  • You don’t need schema validation or type inference
  • You prefer chaining API style

When to Choose CallApi

  • You need request deduplication
  • You want schema validation with type inference
  • You need a plugin system for extensibility
  • You want URL helpers and parameter substitution
  • You need streaming progress tracking

CallApi vs Ofetch

Overview

CallApi is highly inspired by Ofetch. Both share similar philosophies and design patterns.

Key Differences

Both libraries share:
  • Fetch API foundation
  • Automatic JSON handling
  • Retry support with exponential backoff
  • Lifecycle hooks/interceptors
  • Object literal request body support
  • Timeout support
  • TypeScript-first design

Code Comparison

Ofetch:
import { ofetch } from 'ofetch';

const api = ofetch.create({
  baseURL: 'https://api.example.com',
  onRequest: ({ options }) => {
    options.headers = {
      ...options.headers,
      Authorization: `Bearer ${token}`,
    };
  },
});

const users = await api('/users');
CallApi:
import { createFetchClient } from '@zayne-labs/callapi';

const api = createFetchClient({
  baseURL: 'https://api.example.com',
  onRequest: ({ request }) => {
    request.headers.set('Authorization', `Bearer ${token}`);
  },
});

const { data: users } = await api('/users');

When to Choose Ofetch

  • You need a proven, battle-tested library
  • You’re already using it and don’t need extra features
  • You prefer a slightly simpler API

When to Choose CallApi

  • You need request deduplication
  • You want built-in schema validation and type inference
  • You need a plugin system
  • You want streaming progress tracking
  • You need URL parameter substitution
  • You want method prefixes (@get, @post)
  • Smaller bundle size matters

Feature Matrix

Comprehensive comparison of all libraries:
FeatureAxiosKyOfetchCallApi
Core
Fetch-based
Zero Dependencies
Bundle Size13KB5KB8KB<6KB
Request Features
Timeout
Retry Logic
Exponential Backoff⚠️
Request Cancellation
Request Deduplication
URL Param Substitution
Method Prefixes
Response Features
Auto JSON Parsing
Content-Type Detection⚠️
Schema Validation
Streaming Progress
Developer Experience
TypeScript Support⚠️
Type Inference⚠️⚠️
Hooks/Interceptors
Plugin System
Error Handling⚠️
✅ = Full support | ⚠️ = Partial support | ❌ = Not supported

Migration Paths

For detailed migration guides from each library, see:

Summary

CallApi is designed for modern web development: Choose CallApi if you want:
  • Modern, fetch-based API
  • Built-in schema validation with type inference
  • Request deduplication for performance
  • Extensible plugin system
  • Comprehensive TypeScript support
  • Small bundle size (<6KB)
  • All the convenience features you need
Choose other libraries if:
  • Axios: You need IE11 support or have heavy Axios investment
  • Ky: You want absolute minimal API surface
  • Ofetch: You’re already using it and satisfied
CallApi provides the best balance of features, bundle size, and developer experience for modern applications.

Build docs developers (and LLMs) love