@hyper-fetch/axios
v8.2.0
Published
Simple axios adapter for Hyper Fetch
Readme
🏛️ Hyper Fetch Axios
📖 About
This adapter replaces HyperFetch's built-in HTTP engine with Axios. You get all of Axios's features — interceptors, automatic JSON transforms, request/response transforms — while keeping HyperFetch's typed request system, caching, queuing, and React hooks.
🎯 Key Capabilities
- 🔌 One line to switch — Replace the default HTTP engine with Axios without touching your requests
- 🎯 Keep your interceptors — Use existing Axios request/response interceptors and error transforms
- ✨ All HyperFetch features stay — Caching, queuing, types, offline support, React hooks — nothing lost
- 🔧 Bring your own instance — Pass a pre-configured Axios instance with custom defaults and auth headers
🚀 Quick Start
npm install @hyper-fetch/core @hyper-fetch/axios axiosimport { createClient } from "@hyper-fetch/core";
import { AxiosAdapter } from "@hyper-fetch/axios";
const client = createClient({ url: "https://api.example.com" }).setAdapter(AxiosAdapter());📚 Documentation
💡 Examples
Use with Axios interceptors
import axios from "axios";
import { createClient } from "@hyper-fetch/core";
import { AxiosAdapter } from "@hyper-fetch/axios";
const axiosInstance = axios.create({ baseURL: "https://api.example.com" });
axiosInstance.interceptors.request.use((config) => {
config.headers.Authorization = `Bearer ${getToken()}`;
return config;
});
axiosInstance.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) refreshToken();
return Promise.reject(error);
},
);
const client = createClient({ url: "https://api.example.com" }).setAdapter(
AxiosAdapter({ instance: axiosInstance }),
);Create typed requests (same as core)
const getUsers = client.createRequest<{ response: User[] }>()({
endpoint: "/users",
method: "GET",
});
const { data, error } = await getUsers.send();