@rendomnet/apiservice 1.3.4 → 1.3.5
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/README.md +35 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -194,6 +194,41 @@ const result = await api.call({
|
|
|
194
194
|
|
|
195
195
|
If no accountId is provided, ApiService automatically uses 'default' as the account ID.
|
|
196
196
|
|
|
197
|
+
## Request Cancellation
|
|
198
|
+
|
|
199
|
+
ApiService supports request cancellation using the standard `AbortController` API. This allows you to cancel ongoing API requests, including those that are being retried.
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// Create an AbortController
|
|
203
|
+
const controller = new AbortController();
|
|
204
|
+
|
|
205
|
+
// Make an API call with the controller's signal
|
|
206
|
+
const apiPromise = api.call({
|
|
207
|
+
method: 'GET',
|
|
208
|
+
route: '/users',
|
|
209
|
+
abortSignal: controller.signal
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// Cancel the request at any time
|
|
213
|
+
controller.abort();
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
await apiPromise;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (error.name === 'AbortError' || error.message === 'Request aborted') {
|
|
219
|
+
console.log('Request was successfully aborted');
|
|
220
|
+
} else {
|
|
221
|
+
console.error('An error occurred:', error);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The abort functionality works with all features of ApiService:
|
|
227
|
+
- Cancels ongoing requests immediately
|
|
228
|
+
- Prevents retry attempts from starting
|
|
229
|
+
- Works with cached and non-cached requests
|
|
230
|
+
- Compatible with all authentication providers
|
|
231
|
+
|
|
197
232
|
## AuthProvider Interface
|
|
198
233
|
|
|
199
234
|
```typescript
|