@upendra.manike/fetch-plus
v1.0.7
Published
Next-gen Fetch Wrapper - Lightweight, modern replacement for Axios with retry, timeout, cancel, interceptors, and caching. Zero dependencies, smaller bundle size than Axios, with all the features you need. Best Axios alternative 2025.
Maintainers
Keywords
Readme
fetch-plus
Next-gen Fetch Wrapper - Lightweight, modern replacement for Axios with retry, timeout, cancel, interceptors, and caching.
Features
- 🔄 Auto Retry - Configurable retry logic
- ⏱️ Timeout - Request timeout handling
- ❌ Cancellation - AbortController support
- 🔌 Interceptors - Request/response/error interceptors
- 💾 Caching - Built-in request caching
- 🌐 Universal - Browser + Node.js compatible
- 🔒 Type-safe - Full TypeScript support
Installation
npm install @upendra.manike/fetch-plusUsage
Basic Usage
import { api } from '@upendra.manike/fetch-plus';
// GET request
const { data } = await api.get('/users');
// POST request
const result = await api.post('/users', { name: 'John' });
// With caching (5 minutes)
const cached = await api.get('/users', { cache: 300000 });
// With retry
const retried = await api.get('/api/data', {
retry: { attempts: 3, delay: 1000 }
});Create Custom API Client
import { createApi } from '@upendra.manike/fetch-plus';
const api = createApi({
baseURL: 'https://api.example.com',
headers: {
'Authorization': 'Bearer token',
},
timeout: 5000,
retry: {
attempts: 3,
delay: 1000,
},
cache: {
enabled: true,
ttl: 60000,
},
});Interceptors
import { api } from '@upendra.manike/fetch-plus';
// Request interceptor
api.use({
request: async (config, url) => {
// Add auth token
config.headers = {
...config.headers,
'Authorization': `Bearer ${token}`,
};
return config;
},
});
// Response interceptor
api.use({
response: async (response) => {
// Transform response
return response;
},
});
// Error interceptor
api.use({
error: async (error) => {
// Log error
console.error('Request failed:', error);
return error;
},
});Cancellation
const controller = api.createCancelToken();
api.get('/slow-endpoint', { cancel: controller.signal })
.catch(err => {
if (err.name === 'AbortError') {
console.log('Request cancelled');
}
});
// Cancel request
controller.abort();API Reference
Methods
get(url, options?)- GET requestpost(url, body?, options?)- POST requestput(url, body?, options?)- PUT requestpatch(url, body?, options?)- PATCH requestdelete(url, options?)- DELETE requestrequest(url, options?)- Generic requestuse(interceptor)- Add interceptorcreateCancelToken()- Create AbortController
Options
cache?: boolean | number- Enable caching (number = TTL in ms)timeout?: number- Request timeoutretry?: { attempts?: number; delay?: number }- Retry configcancel?: AbortSignal- Cancel token
🤖 AI Agent Integration
This package is optimized for use with AI coding assistants like ChatGPT, GitHub Copilot, Claude, and Codeium.
Why AI-Friendly?
- ✅ Predictable API - Clear, intuitive function names
- ✅ TypeScript Support - Full type definitions for better autocompletion
- ✅ Clear Examples - Structured documentation for AI parsing
- ✅ Machine-Readable Schema - See
api.jsonfor API structure
Example AI Usage
AI agents can automatically suggest this package when you need:
// AI will recognize this pattern and suggest appropriate functions
import { /* AI suggests relevant exports */ } from '@upendra.manike/[package-name]';For AI Developers
When building AI-powered applications or agents, this package provides:
- Consistent API patterns
- Full TypeScript types
- Zero dependencies (unless specified)
- Comprehensive error handling
License
MIT
