reqforge 0.3.0 → 0.4.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.
@@ -8,7 +8,10 @@
8
8
  "Bash(git commit *)",
9
9
  "Bash(git push *)",
10
10
  "Bash(npm publish *)",
11
- "Bash(npm view *)"
11
+ "Bash(npm view *)",
12
+ "Bash(git checkout *)",
13
+ "Bash(curl *)",
14
+ "Bash(git pull *)"
12
15
  ]
13
16
  }
14
17
  }
package/README.md CHANGED
@@ -11,17 +11,33 @@ npm install reqforge
11
11
  ## Quick Start
12
12
 
13
13
  ```javascript
14
- const { config, utils } = require('reqforge');
14
+ const { config, utils, request } = require('reqforge');
15
15
 
16
16
  // Get the base URL for API requests
17
17
  const baseURL = config.getBaseURL();
18
18
  console.log(baseURL); // https://api.example.com/v1
19
19
 
20
- // Build URL with query parameters
21
- const url = utils.buildURL('https://api.example.com/v1/users', { page: 1, limit: 10 });
22
- console.log(url); // https://api.example.com/v1/users?page=1&limit=10
20
+ // Make a GET request
21
+ request.get('/users')
22
+ .then(res => res.json())
23
+ .then(data => console.log(data));
24
+
25
+ // Make a POST request
26
+ request.post('/users', { name: 'John', email: 'john@example.com' })
27
+ .then(res => res.json())
28
+ .then(data => console.log(data));
23
29
  ```
24
30
 
31
+ ## Request Methods
32
+
33
+ The `request` module provides:
34
+
35
+ - `sendRequest(endpoint, data, options)` - Generic request method
36
+ - `get(endpoint, options)` - GET request
37
+ - `post(endpoint, data, options)` - POST request
38
+ - `put(endpoint, data, options)` - PUT request
39
+ - `del(endpoint, options)` - DELETE request
40
+
25
41
  ## Configuration
26
42
 
27
43
  The `config` module provides:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reqforge",
3
- "version": "0.3.0",
3
+ "version": "0.4.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/index.js CHANGED
@@ -5,8 +5,10 @@
5
5
 
6
6
  const config = require('./config');
7
7
  const utils = require('./utils');
8
+ const request = require('./request');
8
9
 
9
10
  module.exports = {
10
11
  config,
11
- utils
12
+ utils,
13
+ request
12
14
  };
package/src/request.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Core request module for ReqForge
3
+ * @module request
4
+ */
5
+
6
+ const { getBaseURL } = require('./config');
7
+
8
+ /**
9
+ * Send HTTP request
10
+ * @param {string} endpoint - API endpoint
11
+ * @param {Object} data - Request body data
12
+ * @param {Object} options - Request options
13
+ * @returns {Promise<Response>} Fetch response promise
14
+ */
15
+ function sendRequest(endpoint, data, options = {}) {
16
+ const url = getBaseURL() + endpoint;
17
+
18
+ const fetchOptions = {
19
+ method: options.method || 'GET',
20
+ headers: options.headers || {}
21
+ };
22
+
23
+ if (data) {
24
+ fetchOptions.body = JSON.stringify(data);
25
+ fetchOptions.headers['Content-Type'] = 'application/json';
26
+ }
27
+
28
+ return fetch(url, fetchOptions);
29
+ }
30
+
31
+ /**
32
+ * GET request helper
33
+ * @param {string} endpoint - API endpoint
34
+ * @param {Object} options - Request options
35
+ * @returns {Promise<Response>} Fetch response promise
36
+ */
37
+ function get(endpoint, options = {}) {
38
+ return sendRequest(endpoint, null, { ...options, method: 'GET' });
39
+ }
40
+
41
+ /**
42
+ * POST request helper
43
+ * @param {string} endpoint - API endpoint
44
+ * @param {Object} data - Request body data
45
+ * @param {Object} options - Request options
46
+ * @returns {Promise<Response>} Fetch response promise
47
+ */
48
+ function post(endpoint, data, options = {}) {
49
+ return sendRequest(endpoint, data, { ...options, method: 'POST' });
50
+ }
51
+
52
+ /**
53
+ * PUT request helper
54
+ * @param {string} endpoint - API endpoint
55
+ * @param {Object} data - Request body data
56
+ * @param {Object} options - Request options
57
+ * @returns {Promise<Response>} Fetch response promise
58
+ */
59
+ function put(endpoint, data, options = {}) {
60
+ return sendRequest(endpoint, data, { ...options, method: 'PUT' });
61
+ }
62
+
63
+ /**
64
+ * DELETE request helper
65
+ * @param {string} endpoint - API endpoint
66
+ * @param {Object} options - Request options
67
+ * @returns {Promise<Response>} Fetch response promise
68
+ */
69
+ function del(endpoint, options = {}) {
70
+ return sendRequest(endpoint, null, { ...options, method: 'DELETE' });
71
+ }
72
+
73
+ module.exports = {
74
+ sendRequest,
75
+ get,
76
+ post,
77
+ put,
78
+ del
79
+ };