Migrating from Axios

An example of how common Axios concepts map to this client. Review each API difference before migrating an application.


Side-by-Side Comparison

Before: Axios
axios.ts
typescript
// BEFORE (Axios)
import axios from 'axios';

const api = axios.create({
  baseURL: 'https://api.example.com',
  timeout: 5000,
});

api.interceptors.request.use(async (config) => {
  const token = await getAuthToken();
  if (token) {
    config.headers.Authorization = `Bearer ${token}`;
  }
  return config;
});

const res = await api.get('/users');
console.log(res.data);
After: react-native-fetch-client
fetch-client.ts
typescript
// AFTER (react-native-fetch-client)
import { createClient } from 'react-native-fetch-client';

const api = createClient({
  baseURL: 'https://api.example.com',
  timeout: 5000,
  // Built-in dynamic Bearer token (no manual interceptor required!)
  bearerToken: async () => await getAuthToken(),
});

// Similar method helper; response and configuration details differ.
const res = await api.get('/users');
console.log(res.data);

Configuration Mapping Table

Axios Conceptreact-native-fetch-client ReplacementNotes
axios.create()createClient() or client.create()Similar factory role; review configuration differences
config.paramsconfig.paramsSame purpose; verify encoding and supported value types
config.headersconfig.headersBoth accept request headers; supported forms differ by type
response.dataresponse.dataBoth expose parsed response data as .data by default
axios-retry pluginretry: { attempts: 3 }Retries are built in and opt-in; configure attempts and policy
axios-cache-interceptorcache: { enabled: true }Optional cache; provide an adapter for persistence