advanced-client-fetch-axios-adapter
v1.0.6
Published
π Axios-compatible adapter for Advanced Client Fetch. Drop-in replacement for Axios with modern fetch-based architecture.
Maintainers
Readme
Advanced Client Fetch - Axios Adapter
π Axios-compatible adapter for Advanced Client Fetch. Drop-in replacement for Axios with modern fetch-based architecture.
β¨ Features
- π― Axios Compatible: Drop-in replacement for Axios
- π Modern Architecture: Built on Advanced Client Fetch
- π Platform Independent: Works on Node.js, Browser, Edge, Deno, Bun
- π¦ Lightweight: Only ~3KB gzipped
- π¨ TypeScript: Full type safety
- π Interceptors: Request and response interceptors
- β‘ Performance: Better than Axios
π¦ Installation
npm install advanced-client-fetch-axios-adapterπ Quick Start
Basic Usage
import { createAxiosAdapter } from 'advanced-client-fetch-axios-adapter';
const axios = createAxiosAdapter({
baseURL: 'https://api.example.com',
timeout: 5000,
headers: {
'Authorization': 'Bearer your-token'
}
});
// Use exactly like Axios
const response = await axios.get('/users');
const newUser = await axios.post('/users', {
name: 'John Doe',
email: '[email protected]'
});With Interceptors
import { createAxiosAdapter } from 'advanced-client-fetch-axios-adapter';
const axios = createAxiosAdapter({
baseURL: 'https://api.example.com'
});
// Request interceptor
axios.interceptors.request.use(
(config) => {
config.headers.Authorization = `Bearer ${getToken()}`;
return config;
},
(error) => Promise.reject(error)
);
// Response interceptor
axios.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) {
// Handle unauthorized
redirectToLogin();
}
return Promise.reject(error);
}
);Advanced Configuration
import { createAxiosAdapter } from 'advanced-client-fetch-axios-adapter';
const axios = createAxiosAdapter({
baseURL: 'https://api.example.com',
timeout: 10000,
headers: {
'Content-Type': 'application/json',
'User-Agent': 'MyApp/1.0.0'
},
validateStatus: (status) => status < 500,
transformRequest: [(data) => JSON.stringify(data)],
transformResponse: [(data) => JSON.parse(data)],
paramsSerializer: (params) => new URLSearchParams(params).toString()
});π Migration from Axios
// Before (Axios)
import axios from 'axios';
const response = await axios.get('/api/users');
// After (Advanced Client Fetch Axios Adapter)
import { createAxiosAdapter } from 'advanced-client-fetch-axios-adapter';
const axios = createAxiosAdapter();
const response = await axios.get('/api/users');π API Reference
createAxiosAdapter(options)
Creates an Axios-compatible client.
Options:
baseURL?: string- Base URL for requeststimeout?: number- Request timeout in millisecondsheaders?: Record<string, string>- Default headersvalidateStatus?: (status: number) => boolean- Status validation functiontransformRequest?: any[]- Request transformerstransformResponse?: any[]- Response transformersparamsSerializer?: (params: any) => string- Params serializer
Methods
get(url, config?)- GET requestpost(url, data?, config?)- POST requestput(url, data?, config?)- PUT requestpatch(url, data?, config?)- PATCH requestdelete(url, config?)- DELETE requesthead(url, config?)- HEAD requestoptions(url, config?)- OPTIONS request
Interceptors
interceptors.request.use(onFulfilled?, onRejected?)- Request interceptorinterceptors.response.use(onFulfilled?, onRejected?)- Response interceptor
π Platform Support
- β Node.js 18+
- β Browsers (modern)
- β Edge Runtime (Vercel, Cloudflare)
- β Deno 1.0+
- β Bun 1.0+
π Bundle Size
- Size: ~3KB gzipped
- Dependencies: Only
advanced-client-fetch
π§ͺ Testing
npm test
npm run test:watch
npm run test:coverageπ€ Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Inspired by Axios
- Built with Advanced Client Fetch
- Powered by native Fetch API
