@jaseeey/request-manager 2.1.0 → 2.1.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/README.md +41 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Should you wish to extend the behaviour, or modify it for your own purposes, the
|
|
|
14
14
|
|
|
15
15
|
## Features
|
|
16
16
|
|
|
17
|
-
- Prevents duplicate simultaneous requests to the same URL and method.
|
|
17
|
+
- Prevents duplicate simultaneous requests to the same client instance, URL, and method.
|
|
18
18
|
- Supports TypeScript for improved type safety and developer experience.
|
|
19
19
|
- Allows for optional onSuccess and onError callbacks to handle responses.
|
|
20
20
|
- Generates both CommonJS (CJS) and ECMAScript Module (ESM) distributions for broad compatibility.
|
|
@@ -31,43 +31,63 @@ npm install @jaseeey/request-manager
|
|
|
31
31
|
|
|
32
32
|
Here's a basic example of how to use the RequestManager library:
|
|
33
33
|
|
|
34
|
-
###
|
|
34
|
+
### Recommended: Default Instance
|
|
35
35
|
|
|
36
36
|
```javascript
|
|
37
|
-
import
|
|
37
|
+
import requestManager from '@jaseeey/request-manager';
|
|
38
38
|
|
|
39
39
|
const client = axios.create();
|
|
40
40
|
const url = 'https://example.com';
|
|
41
41
|
const method = 'GET';
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
// Handle your response here, any processing will only be run once.
|
|
45
|
-
}, err => {
|
|
46
|
-
// Handle your error here
|
|
47
|
-
});
|
|
43
|
+
const response = await requestManager.call(client, method, url);
|
|
48
44
|
```
|
|
49
45
|
|
|
50
|
-
###
|
|
46
|
+
### With Callbacks and Transforming Success Result
|
|
51
47
|
|
|
52
48
|
```javascript
|
|
53
|
-
import
|
|
49
|
+
import requestManager from '@jaseeey/request-manager';
|
|
54
50
|
|
|
55
51
|
const client = axios.create();
|
|
56
52
|
const url = 'https://example.com';
|
|
57
|
-
const method = 'GET';
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
const result = await requestManager.call(
|
|
55
|
+
client,
|
|
56
|
+
'GET',
|
|
57
|
+
url,
|
|
58
|
+
{},
|
|
59
|
+
{},
|
|
60
|
+
res => res.data, // Returning a value changes the resolved result
|
|
61
|
+
err => {
|
|
62
|
+
// Handle your error here
|
|
63
|
+
}
|
|
64
|
+
);
|
|
66
65
|
```
|
|
67
66
|
|
|
67
|
+
### Creating Isolated Managers
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
import { RequestManager } from '@jaseeey/request-manager';
|
|
71
|
+
|
|
72
|
+
const client = axios.create();
|
|
73
|
+
const scopedRequestManager = new RequestManager();
|
|
74
|
+
|
|
75
|
+
const response = await scopedRequestManager.call(client, 'GET', 'https://example.com');
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Legacy Static API (Backward Compatibility)
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
import { RequestManager } from '@jaseeey/request-manager';
|
|
82
|
+
|
|
83
|
+
const response = await RequestManager.call(client, 'GET', 'https://example.com');
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`RequestManager.call(...)` is supported for backward compatibility, but the default instance API is recommended.
|
|
87
|
+
|
|
68
88
|
## API Reference
|
|
69
89
|
|
|
70
|
-
### `call(client, method, url, data, config, onSuccess, onError)`
|
|
90
|
+
### `requestManager.call(client, method, url, data, config, onSuccess, onError)`
|
|
71
91
|
|
|
72
92
|
- `client`: The HTTP client instance used for making requests.
|
|
73
93
|
- `method`: The HTTP method (e.g., 'GET', 'POST').
|
|
@@ -77,6 +97,8 @@ catch (err) {
|
|
|
77
97
|
- `onSuccess` (optional): A callback function that is called when the request is successful. Returning a non-`undefined` value from this callback changes the resolved value of the `call()` promise.
|
|
78
98
|
- `onError` (optional): A callback function that is called when the request fails.
|
|
79
99
|
|
|
100
|
+
`RequestManager.call(...)` is also available as a static compatibility API and delegates to the shared default instance.
|
|
101
|
+
|
|
80
102
|
## Known Limitations
|
|
81
103
|
|
|
82
104
|
### Unified Callback Execution
|