reqforge 0.1.0 → 0.2.0
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 +27 -0
- package/package.json +1 -1
- package/src/config.js +48 -0
- package/src/index.js +5 -1
package/README.md
CHANGED
|
@@ -8,6 +8,33 @@ A lightweight, flexible HTTP client library with request interception, automatic
|
|
|
8
8
|
npm install reqforge
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const { config } = require('reqforge');
|
|
15
|
+
|
|
16
|
+
// Get the base URL for API requests
|
|
17
|
+
const baseURL = config.getBaseURL();
|
|
18
|
+
console.log(baseURL); // https://api.example.com/v1
|
|
19
|
+
|
|
20
|
+
// Merge custom configuration
|
|
21
|
+
const customConfig = config.mergeConfig({
|
|
22
|
+
timeout: 10000,
|
|
23
|
+
headers: {
|
|
24
|
+
'Authorization': 'Bearer your-token'
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
The `config` module provides:
|
|
32
|
+
|
|
33
|
+
- `getBaseURL()` - Get the base URL for API requests
|
|
34
|
+
- `API_VERSION` - Current API version
|
|
35
|
+
- `defaultConfig` - Default configuration object
|
|
36
|
+
- `mergeConfig(customConfig)` - Merge custom configuration with defaults
|
|
37
|
+
|
|
11
38
|
## License
|
|
12
39
|
|
|
13
40
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reqforge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A lightweight, flexible HTTP client library with request interception, automatic retry, and logging capabilities, designed for modern web applications.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
package/src/config.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration module for ReqForge
|
|
3
|
+
* @module config
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const API_VERSION = 'v1';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get the base URL for API requests
|
|
10
|
+
* @returns {string} The base URL with API version
|
|
11
|
+
*/
|
|
12
|
+
function getBaseURL() {
|
|
13
|
+
return `https://api.example.com/${API_VERSION}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Default configuration for requests
|
|
18
|
+
*/
|
|
19
|
+
const defaultConfig = {
|
|
20
|
+
baseURL: getBaseURL(),
|
|
21
|
+
timeout: 5000,
|
|
22
|
+
headers: {
|
|
23
|
+
'Content-Type': 'application/json'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Merge custom configuration with defaults
|
|
29
|
+
* @param {Object} customConfig - Custom configuration to merge
|
|
30
|
+
* @returns {Object} Merged configuration
|
|
31
|
+
*/
|
|
32
|
+
function mergeConfig(customConfig = {}) {
|
|
33
|
+
return {
|
|
34
|
+
...defaultConfig,
|
|
35
|
+
...customConfig,
|
|
36
|
+
headers: {
|
|
37
|
+
...defaultConfig.headers,
|
|
38
|
+
...(customConfig.headers || {})
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
getBaseURL,
|
|
45
|
+
API_VERSION,
|
|
46
|
+
defaultConfig,
|
|
47
|
+
mergeConfig
|
|
48
|
+
};
|