@saifraza/api
v1.0.2
Published
Shared API client for ACS microfrontends
Readme
@saifraza/api
Shared API client for ACS microfrontends with enterprise features.
Features
- Automatic token refresh
- Request/Response interceptors
- Error handling with retry logic
- Request caching
- Request cancellation
- File upload/download with progress
- Multi-tenant support
- SkyWalking distributed tracing
Installation
This package is part of the monorepo workspace. It's automatically linked when you run yarn install from the root.
Usage
Basic Usage
import { createApiClient } from '@saifraza/api';
const apiClient = createApiClient({
baseURL: 'https://api.example.com',
getToken: () => localStorage.getItem('token'),
onUnauthorized: () => {
// Handle 401 errors (e.g., redirect to login)
window.location.href = '/login';
},
notify: (message, type) => {
// Show toast notifications
console.log(`[${type}] ${message}`);
},
});
// Make requests
const data = await apiClient.get('/users');
const newUser = await apiClient.post('/users', { name: 'John' });With Default Singleton
import apiClient from '@saifraza/api';
// Use the default configured instance
const response = await apiClient.get('/users');Building
yarn workspace @saifraza/api build