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 Concept | react-native-fetch-client Replacement | Notes |
|---|---|---|
| axios.create() | createClient() or client.create() | Similar factory role; review configuration differences |
| config.params | config.params | Same purpose; verify encoding and supported value types |
| config.headers | config.headers | Both accept request headers; supported forms differ by type |
| response.data | response.data | Both expose parsed response data as .data by default |
| axios-retry plugin | retry: { attempts: 3 } | Retries are built in and opt-in; configure attempts and policy |
| axios-cache-interceptor | cache: { enabled: true } | Optional cache; provide an adapter for persistence |