kimu-core 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +30 -0
- package/.gitattributes +11 -0
- package/.github/FUNDING.yml +8 -0
- package/.github/copilot-instructions.md +103 -0
- package/.github/kimu-copilot-instructions.md +3779 -0
- package/.github/workflows/deploy-demo.yml +39 -0
- package/AUTHORS.md +20 -0
- package/CHANGELOG.md +20 -0
- package/CODE_GUIDELINES.md +165 -0
- package/CODE_OF_CONDUCT.md +47 -0
- package/CONTRIBUTING.md +62 -0
- package/FUNDING.md +31 -0
- package/ISSUE_GUIDELINES.md +74 -0
- package/LICENSE +17 -0
- package/LICENSE.it.md +17 -0
- package/MPL-2.0.txt +373 -0
- package/NOTICE +65 -0
- package/README-KIMU.md +40 -0
- package/README.it.md +208 -0
- package/README.md +266 -0
- package/SECURITY.md +64 -0
- package/docs/get-started-en.md +207 -0
- package/docs/images/icon.svg +64 -0
- package/docs/images/logo_kimu.png +0 -0
- package/docs/index.md +29 -0
- package/env/dev.config.json +6 -0
- package/env/local.config.json +6 -0
- package/env/prod.config.json +6 -0
- package/env/staging.config.json +6 -0
- package/env/test.config.json +4 -0
- package/icon.svg +10 -0
- package/logo_kimu.png +0 -0
- package/package.json +79 -0
- package/public/favicon.svg +64 -0
- package/public/logo_kimu.svg +1 -0
- package/scripts/build-all-config.js +59 -0
- package/scripts/build-all-core.js +65 -0
- package/scripts/build-all-extensions.js +64 -0
- package/scripts/build-all-modules.js +99 -0
- package/scripts/build-extension.js +60 -0
- package/scripts/clear-kimu-build.js +31 -0
- package/scripts/generate-kimu-build-config.js +79 -0
- package/scripts/install-module.js +162 -0
- package/scripts/list-modules.js +109 -0
- package/scripts/minify-css-assets.js +82 -0
- package/scripts/remove-module.js +122 -0
- package/scripts/utils/fix-imports.js +85 -0
- package/src/assets/index.css +43 -0
- package/src/assets/kimu-style.css +84 -0
- package/src/assets/style.css +116 -0
- package/src/config/kimu-base-config.json +5 -0
- package/src/core/index.ts +47 -0
- package/src/core/kimu-app.ts +76 -0
- package/src/core/kimu-asset-manager.ts +167 -0
- package/src/core/kimu-component-element.ts +325 -0
- package/src/core/kimu-component.ts +33 -0
- package/src/core/kimu-engine.ts +188 -0
- package/src/core/kimu-extension-manager.ts +281 -0
- package/src/core/kimu-global-styles.ts +136 -0
- package/src/core/kimu-module-manager.ts +69 -0
- package/src/core/kimu-module.ts +21 -0
- package/src/core/kimu-path-config.ts +127 -0
- package/src/core/kimu-reactive.ts +196 -0
- package/src/core/kimu-render.ts +91 -0
- package/src/core/kimu-store.ts +147 -0
- package/src/core/kimu-types.ts +65 -0
- package/src/extensions/.gitkeep +0 -0
- package/src/extensions/extensions-manifest.json +13 -0
- package/src/extensions/kimu-home/component.ts +80 -0
- package/src/extensions/kimu-home/lang/en.json +5 -0
- package/src/extensions/kimu-home/lang/it.json +5 -0
- package/src/extensions/kimu-home/style.css +61 -0
- package/src/extensions/kimu-home/view.html +51 -0
- package/src/index.html +26 -0
- package/src/main.ts +68 -0
- package/src/modules/.gitkeep +0 -0
- package/src/modules/README.md +79 -0
- package/src/modules/i18n/README.it.md +63 -0
- package/src/modules/i18n/README.md +63 -0
- package/src/modules/i18n/kimu-global-lang.ts +26 -0
- package/src/modules/i18n/kimu-i18n-service.ts +108 -0
- package/src/modules/i18n/manifest.json +22 -0
- package/src/modules/i18n/module.ts +39 -0
- package/src/modules/modules-manifest.json +12 -0
- package/src/modules-repository/README.md +108 -0
- package/src/modules-repository/api-axios/CHANGELOG.md +48 -0
- package/src/modules-repository/api-axios/QUICK-REFERENCE.md +178 -0
- package/src/modules-repository/api-axios/README.md +304 -0
- package/src/modules-repository/api-axios/api-axios-service.ts +355 -0
- package/src/modules-repository/api-axios/examples.ts +293 -0
- package/src/modules-repository/api-axios/index.ts +19 -0
- package/src/modules-repository/api-axios/interfaces.ts +71 -0
- package/src/modules-repository/api-axios/module.ts +41 -0
- package/src/modules-repository/api-core/CHANGELOG.md +42 -0
- package/src/modules-repository/api-core/QUICK-REFERENCE.md +192 -0
- package/src/modules-repository/api-core/README.md +435 -0
- package/src/modules-repository/api-core/api-core-service.ts +289 -0
- package/src/modules-repository/api-core/examples.ts +432 -0
- package/src/modules-repository/api-core/index.ts +8 -0
- package/src/modules-repository/api-core/interfaces.ts +83 -0
- package/src/modules-repository/api-core/module.ts +30 -0
- package/src/modules-repository/event-bus/README.md +273 -0
- package/src/modules-repository/event-bus/event-bus-service.ts +176 -0
- package/src/modules-repository/event-bus/module.ts +30 -0
- package/src/modules-repository/i18n/README.it.md +63 -0
- package/src/modules-repository/i18n/README.md +63 -0
- package/src/modules-repository/i18n/kimu-global-lang.ts +26 -0
- package/src/modules-repository/i18n/kimu-i18n-service.ts +108 -0
- package/src/modules-repository/i18n/manifest.json +22 -0
- package/src/modules-repository/i18n/module.ts +39 -0
- package/src/modules-repository/notification/README.md +423 -0
- package/src/modules-repository/notification/module.ts +30 -0
- package/src/modules-repository/notification/notification-service.ts +436 -0
- package/src/modules-repository/router/README.it.md +39 -0
- package/src/modules-repository/router/README.md +39 -0
- package/src/modules-repository/router/manifest.json +21 -0
- package/src/modules-repository/router/module.ts +23 -0
- package/src/modules-repository/router/router.ts +144 -0
- package/src/modules-repository/state/README.md +409 -0
- package/src/modules-repository/state/module.ts +30 -0
- package/src/modules-repository/state/state-service.ts +296 -0
- package/src/modules-repository/theme/README.md +267 -0
- package/src/modules-repository/theme/module.ts +30 -0
- package/src/modules-repository/theme/pre-build.js +40 -0
- package/src/modules-repository/theme/theme-service.ts +389 -0
- package/src/modules-repository/theme/themes/theme-cherry-blossom.css +78 -0
- package/src/modules-repository/theme/themes/theme-cozy.css +111 -0
- package/src/modules-repository/theme/themes/theme-cyberpunk.css +150 -0
- package/src/modules-repository/theme/themes/theme-dark.css +79 -0
- package/src/modules-repository/theme/themes/theme-forest.css +171 -0
- package/src/modules-repository/theme/themes/theme-gold.css +100 -0
- package/src/modules-repository/theme/themes/theme-high-contrast.css +126 -0
- package/src/modules-repository/theme/themes/theme-lava.css +101 -0
- package/src/modules-repository/theme/themes/theme-lavender.css +90 -0
- package/src/modules-repository/theme/themes/theme-light.css +79 -0
- package/src/modules-repository/theme/themes/theme-matrix.css +103 -0
- package/src/modules-repository/theme/themes/theme-midnight.css +81 -0
- package/src/modules-repository/theme/themes/theme-nord.css +94 -0
- package/src/modules-repository/theme/themes/theme-ocean.css +84 -0
- package/src/modules-repository/theme/themes/theme-retro80s.css +343 -0
- package/src/modules-repository/theme/themes/theme-sunset.css +62 -0
- package/src/modules-repository/theme/themes-config.d.ts +27 -0
- package/src/modules-repository/theme/themes-config.json +213 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +33 -0
- package/vite.config.ts +99 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Changelog - API Axios Module
|
|
2
|
+
|
|
3
|
+
All notable changes to the api-axios module will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2025-11-01
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of api-axios module
|
|
12
|
+
- Full Axios-based HTTP client implementation
|
|
13
|
+
- Request/response interceptors support
|
|
14
|
+
- Automatic retry logic with exponential backoff
|
|
15
|
+
- Request cancellation support via cancel tokens
|
|
16
|
+
- Upload/download progress tracking
|
|
17
|
+
- Response caching with configurable TTL
|
|
18
|
+
- Complete TypeScript type definitions
|
|
19
|
+
- Comprehensive documentation and examples
|
|
20
|
+
- Migration guide from api-core
|
|
21
|
+
- Error transformation and standardized error handling
|
|
22
|
+
- Support for all HTTP methods (GET, POST, PUT, PATCH, DELETE)
|
|
23
|
+
- Query parameters and custom headers support
|
|
24
|
+
- Timeout configuration per request
|
|
25
|
+
- Credentials (cookies) support
|
|
26
|
+
|
|
27
|
+
### Features Over api-core
|
|
28
|
+
- **Interceptors**: Add custom logic before/after requests
|
|
29
|
+
- **Retry Logic**: Automatic retry with exponential backoff
|
|
30
|
+
- **Cancellation**: Cancel pending requests when needed
|
|
31
|
+
- **Progress**: Track upload/download progress in real-time
|
|
32
|
+
- **Caching**: Cache GET responses to reduce network calls
|
|
33
|
+
- **Better Errors**: Enhanced error handling with original error preservation
|
|
34
|
+
|
|
35
|
+
### Dependencies
|
|
36
|
+
- axios: ^1.6.0 (external dependency)
|
|
37
|
+
|
|
38
|
+
## [Unreleased]
|
|
39
|
+
|
|
40
|
+
### Planned Features
|
|
41
|
+
- Request deduplication (prevent duplicate concurrent requests)
|
|
42
|
+
- Request queue management
|
|
43
|
+
- Offline request queueing
|
|
44
|
+
- Custom retry strategies
|
|
45
|
+
- Response schema validation
|
|
46
|
+
- Mock mode for testing
|
|
47
|
+
- Request/response logging
|
|
48
|
+
- Metrics and performance tracking
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# API Axios - Quick Reference
|
|
2
|
+
|
|
3
|
+
## Import
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { apiAxiosService } from '../../modules/api-axios/api-axios-service';
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Basic Methods
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
// GET request
|
|
13
|
+
const response = await apiAxiosService.get(url, config);
|
|
14
|
+
|
|
15
|
+
// POST request
|
|
16
|
+
const response = await apiAxiosService.post(url, data, config);
|
|
17
|
+
|
|
18
|
+
// PUT request
|
|
19
|
+
const response = await apiAxiosService.put(url, data, config);
|
|
20
|
+
|
|
21
|
+
// PATCH request
|
|
22
|
+
const response = await apiAxiosService.patch(url, data, config);
|
|
23
|
+
|
|
24
|
+
// DELETE request
|
|
25
|
+
const response = await apiAxiosService.delete(url, config);
|
|
26
|
+
|
|
27
|
+
// Generic request with method
|
|
28
|
+
const response = await apiAxiosService.request(method, url, data, config);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Common Use Cases
|
|
32
|
+
|
|
33
|
+
### With Query Parameters
|
|
34
|
+
```typescript
|
|
35
|
+
const response = await apiAxiosService.get('https://api.example.com/users', {
|
|
36
|
+
params: { page: 1, limit: 10 }
|
|
37
|
+
});
|
|
38
|
+
// Calls: https://api.example.com/users?page=1&limit=10
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### With Custom Headers
|
|
42
|
+
```typescript
|
|
43
|
+
const response = await apiAxiosService.get('https://api.example.com/data', {
|
|
44
|
+
headers: {
|
|
45
|
+
'Authorization': 'Bearer token123',
|
|
46
|
+
'X-Custom-Header': 'value'
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### With Timeout
|
|
52
|
+
```typescript
|
|
53
|
+
const response = await apiAxiosService.get('https://api.example.com/data', {
|
|
54
|
+
timeout: 5000 // 5 seconds
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### With Retry
|
|
59
|
+
```typescript
|
|
60
|
+
const response = await apiAxiosService.request('GET', 'https://api.example.com/data', null, {
|
|
61
|
+
retries: 3,
|
|
62
|
+
retryDelay: 1000
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### With Cache
|
|
67
|
+
```typescript
|
|
68
|
+
const response = await apiAxiosService.get('https://api.example.com/data', {
|
|
69
|
+
useCache: true
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Configure cache TTL
|
|
73
|
+
apiAxiosService.setCacheTTL(10 * 60 * 1000); // 10 minutes
|
|
74
|
+
|
|
75
|
+
// Clear cache
|
|
76
|
+
apiAxiosService.clearCache();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### With Progress Tracking
|
|
80
|
+
```typescript
|
|
81
|
+
const response = await apiAxiosService.post('https://api.example.com/upload', formData, {
|
|
82
|
+
onUploadProgress: (event) => {
|
|
83
|
+
const percent = Math.round((event.loaded * 100) / event.total);
|
|
84
|
+
console.log(`Upload: ${percent}%`);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### With Cancellation
|
|
90
|
+
```typescript
|
|
91
|
+
const cancelToken = apiAxiosService.createCancelToken();
|
|
92
|
+
|
|
93
|
+
const promise = apiAxiosService.get('https://api.example.com/data', {
|
|
94
|
+
axiosConfig: { cancelToken: cancelToken.token }
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Cancel if needed
|
|
98
|
+
cancelToken.cancel('User cancelled');
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Interceptors
|
|
102
|
+
|
|
103
|
+
### Request Interceptor
|
|
104
|
+
```typescript
|
|
105
|
+
apiAxiosService.addRequestInterceptor(async (config) => {
|
|
106
|
+
config.headers = config.headers || {};
|
|
107
|
+
config.headers['Authorization'] = 'Bearer token';
|
|
108
|
+
return config;
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Response Interceptor
|
|
113
|
+
```typescript
|
|
114
|
+
apiAxiosService.addResponseInterceptor(async (response) => {
|
|
115
|
+
console.log('Response:', response.status);
|
|
116
|
+
return response;
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Error Interceptor
|
|
121
|
+
```typescript
|
|
122
|
+
apiAxiosService.addErrorInterceptor(async (error) => {
|
|
123
|
+
if (error.status === 401) {
|
|
124
|
+
// Handle unauthorized
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## TypeScript Types
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import type { ApiResponse, ApiError, ApiRequestConfig } from '../../modules/api-axios';
|
|
133
|
+
|
|
134
|
+
interface User {
|
|
135
|
+
id: number;
|
|
136
|
+
name: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const response = await apiAxiosService.get<User>('https://api.example.com/user/1');
|
|
140
|
+
// response.data is typed as User
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Error Handling
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
try {
|
|
147
|
+
const response = await apiAxiosService.get('https://api.example.com/data');
|
|
148
|
+
console.log(response.data);
|
|
149
|
+
} catch (error: any) {
|
|
150
|
+
console.error('Status:', error.status);
|
|
151
|
+
console.error('Message:', error.message);
|
|
152
|
+
console.error('Data:', error.data);
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Response Format
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
{
|
|
160
|
+
data: any, // Response data
|
|
161
|
+
status: number, // HTTP status code
|
|
162
|
+
statusText: string, // HTTP status text
|
|
163
|
+
headers: {}, // Response headers
|
|
164
|
+
config: {} // Original request config
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Migration from api-core
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
// Simply replace the import
|
|
172
|
+
// From:
|
|
173
|
+
import { apiCoreService } from '../../modules/api-core/api-core-service';
|
|
174
|
+
// To:
|
|
175
|
+
import { apiAxiosService } from '../../modules/api-axios/api-axios-service';
|
|
176
|
+
|
|
177
|
+
// All basic methods work the same!
|
|
178
|
+
```
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# API Axios Module
|
|
2
|
+
|
|
3
|
+
Advanced HTTP client module for KIMU Framework based on the **Axios** library.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The `api-axios` module provides an enhanced HTTP client with advanced features like interceptors, automatic retries, request cancellation, progress tracking, and response caching.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
### ✨ Advanced Features Over api-core
|
|
12
|
+
|
|
13
|
+
1. **Request/Response Interceptors**
|
|
14
|
+
- Modify requests before they are sent
|
|
15
|
+
- Transform responses before they reach your code
|
|
16
|
+
- Handle errors globally
|
|
17
|
+
|
|
18
|
+
2. **Automatic Retry Logic**
|
|
19
|
+
- Configurable retry attempts
|
|
20
|
+
- Exponential backoff strategy
|
|
21
|
+
- Retry only on specific error conditions
|
|
22
|
+
|
|
23
|
+
3. **Request Cancellation**
|
|
24
|
+
- Cancel pending requests
|
|
25
|
+
- Avoid memory leaks from unmounted components
|
|
26
|
+
- Manage concurrent requests
|
|
27
|
+
|
|
28
|
+
4. **Progress Tracking**
|
|
29
|
+
- Upload progress callbacks
|
|
30
|
+
- Download progress callbacks
|
|
31
|
+
- Real-time feedback for large transfers
|
|
32
|
+
|
|
33
|
+
5. **Response Caching**
|
|
34
|
+
- Cache GET requests
|
|
35
|
+
- Configurable TTL (Time To Live)
|
|
36
|
+
- Reduce network traffic and improve performance
|
|
37
|
+
|
|
38
|
+
6. **Better Error Handling**
|
|
39
|
+
- Standardized error format
|
|
40
|
+
- Original error preservation
|
|
41
|
+
- Error interceptors for global handling
|
|
42
|
+
|
|
43
|
+
#### 📋 Feature Comparison: api-core vs api-axios
|
|
44
|
+
|
|
45
|
+
| Funzione | api-core | api-axios |
|
|
46
|
+
|-------------------------------|:--------:|:---------:|
|
|
47
|
+
| HTTP Methods | ✅ | ✅ |
|
|
48
|
+
| Query Parameters | ✅ | ✅ |
|
|
49
|
+
| Custom Headers | ✅ | ✅ |
|
|
50
|
+
| Timeout | ✅ | ✅ |
|
|
51
|
+
| Request Interceptors | ❌ | ✅ |
|
|
52
|
+
| Response Interceptors | ❌ | ✅ |
|
|
53
|
+
| Error Interceptors | ❌ | ✅ |
|
|
54
|
+
| Automatic Retry | ❌ | ✅ |
|
|
55
|
+
| Request Cancellation | ❌ | ✅ |
|
|
56
|
+
| Progress Tracking | ❌ | ✅ |
|
|
57
|
+
| Response Caching | ❌ | ✅ |
|
|
58
|
+
| Bundle Size | ~2KB | ~15KB |
|
|
59
|
+
| Dependencies | 0 | axios |
|
|
60
|
+
|
|
61
|
+
**Legenda:** ✅ = supportato, ❌ = non supportato
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
The module is already part of KIMU-Core. To use it:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm install axios
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Basic Usage
|
|
72
|
+
|
|
73
|
+
### Import the Service
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { apiAxiosService } from '../../modules/api-axios/api-axios-service';
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Simple GET Request
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const response = await apiAxiosService.get('https://api.example.com/data');
|
|
83
|
+
console.log(response.data);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### POST Request with Data
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const response = await apiAxiosService.post(
|
|
90
|
+
'https://api.example.com/users',
|
|
91
|
+
{ name: 'John', email: 'john@example.com' }
|
|
92
|
+
);
|
|
93
|
+
console.log(response.data);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Advanced Features
|
|
97
|
+
|
|
98
|
+
### Request with Retry
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const response = await apiAxiosService.request(
|
|
102
|
+
'GET',
|
|
103
|
+
'https://api.example.com/data',
|
|
104
|
+
null,
|
|
105
|
+
{
|
|
106
|
+
retries: 3, // Retry up to 3 times
|
|
107
|
+
retryDelay: 1000 // Start with 1 second delay (exponential backoff)
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Cached GET Request
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
// First call - fetches from server
|
|
116
|
+
const response1 = await apiAxiosService.get(
|
|
117
|
+
'https://api.example.com/data',
|
|
118
|
+
{ useCache: true }
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Second call - returns cached data (if within TTL)
|
|
122
|
+
const response2 = await apiAxiosService.get(
|
|
123
|
+
'https://api.example.com/data',
|
|
124
|
+
{ useCache: true }
|
|
125
|
+
);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Configure Cache TTL
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// Set cache to expire after 10 minutes
|
|
132
|
+
apiAxiosService.setCacheTTL(10 * 60 * 1000);
|
|
133
|
+
|
|
134
|
+
// Clear all cached data
|
|
135
|
+
apiAxiosService.clearCache();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Request with Progress Tracking
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const response = await apiAxiosService.post(
|
|
142
|
+
'https://api.example.com/upload',
|
|
143
|
+
formData,
|
|
144
|
+
{
|
|
145
|
+
onUploadProgress: (event) => {
|
|
146
|
+
const percentComplete = Math.round((event.loaded * 100) / event.total);
|
|
147
|
+
console.log(`Upload: ${percentComplete}%`);
|
|
148
|
+
},
|
|
149
|
+
onDownloadProgress: (event) => {
|
|
150
|
+
const percentComplete = Math.round((event.loaded * 100) / event.total);
|
|
151
|
+
console.log(`Download: ${percentComplete}%`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Request Cancellation
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// Create a cancel token
|
|
161
|
+
const cancelToken = apiAxiosService.createCancelToken();
|
|
162
|
+
|
|
163
|
+
// Make a request with the cancel token
|
|
164
|
+
const requestPromise = apiAxiosService.get(
|
|
165
|
+
'https://api.example.com/large-data',
|
|
166
|
+
{
|
|
167
|
+
axiosConfig: {
|
|
168
|
+
cancelToken: cancelToken.token
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// Cancel the request if needed
|
|
174
|
+
cancelToken.cancel('User cancelled the request');
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Request Interceptor
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// Add authentication token to all requests
|
|
181
|
+
apiAxiosService.addRequestInterceptor(async (config) => {
|
|
182
|
+
const token = await getAuthToken();
|
|
183
|
+
config.headers = config.headers || {};
|
|
184
|
+
config.headers['Authorization'] = `Bearer ${token}`;
|
|
185
|
+
return config;
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Response Interceptor
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
// Transform all responses
|
|
193
|
+
apiAxiosService.addResponseInterceptor(async (response) => {
|
|
194
|
+
console.log('Response received:', response.status);
|
|
195
|
+
// You can modify the response here
|
|
196
|
+
return response;
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Error Interceptor
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
// Handle errors globally
|
|
204
|
+
apiAxiosService.addErrorInterceptor(async (error) => {
|
|
205
|
+
if (error.status === 401) {
|
|
206
|
+
console.log('Unauthorized - redirecting to login');
|
|
207
|
+
// Redirect to login page
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Migration from api-core
|
|
213
|
+
|
|
214
|
+
The `api-axios` module maintains the same interface as `api-core` for basic operations, making migration simple:
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
// Before (api-core)
|
|
218
|
+
import { apiCoreService } from '../../modules/api-core/api-core-service';
|
|
219
|
+
const response = await apiCoreService.get('https://api.example.com/data');
|
|
220
|
+
|
|
221
|
+
// After (api-axios) - same interface!
|
|
222
|
+
import { apiAxiosService } from '../../modules/api-axios/api-axios-service';
|
|
223
|
+
const response = await apiAxiosService.get('https://api.example.com/data');
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## When to Use api-axios vs api-core
|
|
227
|
+
|
|
228
|
+
### Use **api-core** when:
|
|
229
|
+
- You need a minimal, zero-dependency solution
|
|
230
|
+
- Your requests are simple and don't need advanced features
|
|
231
|
+
- Bundle size is critical
|
|
232
|
+
- You want maximum control over the HTTP implementation
|
|
233
|
+
|
|
234
|
+
### Use **api-axios** when:
|
|
235
|
+
- You need request/response interceptors
|
|
236
|
+
- You want automatic retry logic
|
|
237
|
+
- You need request cancellation
|
|
238
|
+
- You want upload/download progress tracking
|
|
239
|
+
- Response caching would improve performance
|
|
240
|
+
- You're building a complex application with many API calls
|
|
241
|
+
|
|
242
|
+
## Performance Considerations
|
|
243
|
+
|
|
244
|
+
- **Bundle Size**: Axios adds ~13KB (minified + gzipped) to your bundle
|
|
245
|
+
- **Memory**: Caching consumes memory - use `clearCache()` periodically
|
|
246
|
+
- **Network**: Retries increase network traffic - use wisely
|
|
247
|
+
|
|
248
|
+
## Error Handling
|
|
249
|
+
|
|
250
|
+
All errors are transformed to the standard `ApiError` format:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
try {
|
|
254
|
+
const response = await apiAxiosService.get('https://api.example.com/data');
|
|
255
|
+
} catch (error: ApiError) {
|
|
256
|
+
console.error('Status:', error.status);
|
|
257
|
+
console.error('Message:', error.message);
|
|
258
|
+
console.error('Data:', error.data);
|
|
259
|
+
console.error('Original:', error.originalError);
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## TypeScript Support
|
|
264
|
+
|
|
265
|
+
Full TypeScript support with generic types:
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
interface User {
|
|
269
|
+
id: number;
|
|
270
|
+
name: string;
|
|
271
|
+
email: string;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const response = await apiAxiosService.get<User>('https://api.example.com/user/1');
|
|
275
|
+
// response.data is typed as User
|
|
276
|
+
console.log(response.data.name);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Best Practices
|
|
280
|
+
|
|
281
|
+
1. **Use interceptors for cross-cutting concerns** (auth, logging, error handling)
|
|
282
|
+
2. **Enable caching for static or slowly-changing data**
|
|
283
|
+
3. **Use retry logic for non-critical requests**
|
|
284
|
+
4. **Cancel requests when components unmount**
|
|
285
|
+
5. **Track progress for large file uploads/downloads**
|
|
286
|
+
6. **Set appropriate timeouts** for different types of requests
|
|
287
|
+
7. **Clear cache periodically** to manage memory
|
|
288
|
+
|
|
289
|
+
## Dependencies
|
|
290
|
+
|
|
291
|
+
- `axios`: ^1.6.0 (peer dependency)
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
This module is part of KIMU Framework and follows the same license (MPL-2.0).
|
|
296
|
+
|
|
297
|
+
## Author
|
|
298
|
+
|
|
299
|
+
**UnicòVerso** - Marco Di Pasquale
|
|
300
|
+
|
|
301
|
+
## Related
|
|
302
|
+
|
|
303
|
+
- [api-core](../api-core/README.md) - Minimal native HTTP client
|
|
304
|
+
- [KIMU Framework](https://github.com/UnicoVerso/kimu-core)
|