api-zero is a modern, lightweight, and type-safe HTTP client for React and TypeScript. It is designed to be the perfect companion for data fetching libraries like TanStack Query or SWR, providing a robust foundation for your API interactions.
- 🚀 Lightweight & Modern: Built on top of the native Fetch API.
- 🔒 Type-Safe: First-class TypeScript support with generic response types.
- ⚛️ React Integration: Dedicated hooks and provider for seamless React usage.
- 🔄 Smart Retries: Configurable retry system with exponential backoff.
- 🛑 Interceptors: Powerful request and response interceptors.
- 📦 Modular: Separate core and React packages.
npm install @api-zero/core @api-zero/react
# or
pnpm add @api-zero/core @api-zero/react
# or
yarn add @api-zero/core @api-zero/reactimport { createClient } from '@api-zero/core';
export const api = createClient({
baseURL: 'https://api.example.com',
headers: {
'Content-Type': 'application/json',
},
});Wrap your app with ApiProvider:
import { ApiProvider } from '@api-zero/react';
import { api } from './api';
function App() {
return (
<ApiProvider config={api.getConfig()}>
<YourApp />
</ApiProvider>
);
}Use the useApi hook:
import { useApi } from '@api-zero/react';
function UserList() {
const client = useApi();
const fetchUsers = async () => {
const users = await client.get('/users');
console.log(users);
};
return <button onClick={fetchUsers}>Load Users</button>;
}Visit our documentation site for full details, guides, and API reference.
MIT