rock-req 5.1.3 → 5.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 -9
- package/index.js +10 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<h1 align="center" style="border-bottom:none;">Rock-req</h1>
|
|
7
7
|
|
|
8
8
|
<p align="center">⭐️⭐️ Ensure your HTTP requests always reach their destination as <b>efficiently</b> as possible! ⭐️⭐️</p>
|
|
9
|
-
<p align="center">Tested on Mac, Linux, Windows with NodeJS 16, 18, 19, 20</p>
|
|
9
|
+
<p align="center">Tested on Mac, Linux, Windows with NodeJS 16, 18, 19, 20, 22, 24, 25</p>
|
|
10
10
|
|
|
11
11
|
[![npm][npm-image]][npm-url] [![ci][ci-image]][ci-url] [![javascript style guide][standard-image]][standard-url]
|
|
12
12
|
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
## 🔥 Why?
|
|
21
21
|
|
|
22
|
-
In most existing libraries (
|
|
22
|
+
In most existing libraries (2025):
|
|
23
23
|
|
|
24
24
|
- Managing **reliable retries** is difficult, tricky with streams and not battle-tested
|
|
25
25
|
- Using **multiple forward proxies** has several benefits like **higher availability** and **increased bandwidth** but
|
|
@@ -42,6 +42,7 @@ It also supports many features:
|
|
|
42
42
|
- Keep Alive by default (3000ms)
|
|
43
43
|
- Composable
|
|
44
44
|
- Timeouts
|
|
45
|
+
- Promises interface
|
|
45
46
|
- HTTPS / HTTP
|
|
46
47
|
- Composes well with npm packages for features like cookies, proxies, form data, & OAuth
|
|
47
48
|
- Keep 98% of the `simple-get` API (fork source)
|
|
@@ -51,7 +52,25 @@ When the callback is called, the request is 100% finished, even with streams.
|
|
|
51
52
|
|
|
52
53
|
## 🚀 Benchmark Rock-req vs got, axios, node-fetch, phin, simple-get, superagent, ...
|
|
53
54
|
|
|
54
|
-
Stop using "slow
|
|
55
|
+
Stop using "slow-by-default" and "false-light" HTTP request libraries!
|
|
56
|
+
|
|
57
|
+
**2025-11-14 on MacBook Pro M4 Max with all dependencies updated on this date**
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
| Library | NodeJS 22 | NodeJS 24 | NodeJS 25 | Bun v1.3.2 | Size deps inc (2025/2023) |
|
|
61
|
+
|--------------|---------------:|---------------:|---------------:|---------------:|---------------------------:|
|
|
62
|
+
| rock-req 🙋♂️ | 26842 req/s | 26782 req/s | 26179 req/s | 21229 req/s | 152 LOC (+5%) |
|
|
63
|
+
| simple-get | 26532 req/s | 26802 req/s | 25954 req/s | 21187 req/s | 317 LOC (+0%) |
|
|
64
|
+
| axios | 4110 req/s | 3999 req/s | 3996 req/s | 14788 req/s | 19883 LOC (+42%) |
|
|
65
|
+
| got | 14786 req/s | 15234 req/s | 15149 req/s | 15287 req/s | 16904 LOC (+83%) |
|
|
66
|
+
| fetch | 15676 req/s | 16252 req/s | 15784 req/s | 27675 req/s | 54211 LOC (+306%) |
|
|
67
|
+
| request | 17102 req/s | 14586 req/s | 14346 req/s | 18202 req/s | 58057 LOC (+24%) |
|
|
68
|
+
| superagent | 3862 req/s | 3979 req/s | 3889 req/s | 19271 req/s | 31913 LOC (+98%) |
|
|
69
|
+
| phin | 15549 req/s | 14160 req/s | 13915 req/s | 15430 req/s | 20064 LOC (+5960%) |
|
|
70
|
+
| _undici_* | 32480 req/s | 33272 req/s | 32738 req/s | 25961 req/s | 23235 LOC (+43%) |
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
**2023-04-19 on Macbook Pro M1 Max with all dependencies updated on this date**
|
|
55
74
|
|
|
56
75
|
|
|
57
76
|
| Library | NodeJS 16 | NodeJS 18 | NodeJS 20* | Size deps inc. |
|
|
@@ -67,14 +86,13 @@ Stop using "slow by-default" and "false-light" HTTP request libraries!
|
|
|
67
86
|
| _undici_* | 24095 req/s | 24378 req/s | 24191 req/s | 16225 LOC |
|
|
68
87
|
|
|
69
88
|
|
|
70
|
-
>
|
|
71
|
-
|
|
72
|
-
> `undici` is a low-level API, faster alternative to the native NodeJS http module. It is the glass ceiling limit for NodeJS.
|
|
89
|
+
> Since Node.js 20, HTTP keep-alive is activated by default, just like in `rock-req`. This improves the overall performance of all frameworks.
|
|
73
90
|
|
|
74
|
-
> `
|
|
91
|
+
> `undici` is a low-level API and a faster alternative to the native Node.js HTTP module. It represents the performance ceiling for Node.js.
|
|
75
92
|
|
|
76
|
-
>
|
|
93
|
+
> `rock-req` uses only the native Node.js HTTP module and provides many high-level features — far more than `phin` and `simple-get` — with fewer lines of code.
|
|
77
94
|
|
|
95
|
+
> Interestingly, the differences are less visible on Bun.sh.
|
|
78
96
|
|
|
79
97
|
## Install
|
|
80
98
|
|
|
@@ -92,7 +110,7 @@ This packaged in maintained by Carbone:
|
|
|
92
110
|
|
|
93
111
|
<p>
|
|
94
112
|
<a href="https://carbone.io" alt="Carbone.io - Efficient PDF / DOCX / XLSX / CSV / HTML / XML generator with templates and JSON">
|
|
95
|
-
<img src="https://
|
|
113
|
+
<img src="https://carbone.io/img/carbone-logo.svg" alt="Carbone.io logo" height="60"/>
|
|
96
114
|
</a>
|
|
97
115
|
</p>
|
|
98
116
|
|
package/index.js
CHANGED
|
@@ -76,7 +76,7 @@ function extend (defaultOptions = {}) {
|
|
|
76
76
|
return cb(err)
|
|
77
77
|
}
|
|
78
78
|
let data = Buffer.concat(chunks)
|
|
79
|
-
if (opts.json) {
|
|
79
|
+
if (opts.json && opts.jsonResponse !== false) {
|
|
80
80
|
try { data = data.length > 0 ? JSON.parse(data.toString()) : null } catch (e) { return cb(e, response, data) }
|
|
81
81
|
}
|
|
82
82
|
cb(null, response, data)
|
|
@@ -148,6 +148,7 @@ function extend (defaultOptions = {}) {
|
|
|
148
148
|
return req
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
rock.promises = {};
|
|
151
152
|
;['get', 'post', 'put', 'patch', 'head', 'delete', 'getJSON', 'postJSON', 'putJSON', 'patchJSON', 'headJSON', 'deleteJSON'].forEach(method => {
|
|
152
153
|
const jsonShortcut = /JSON$/.test(method) === true
|
|
153
154
|
const methodShortcut = jsonShortcut === true ? method.toUpperCase().slice(0, -4) : method.toUpperCase()
|
|
@@ -157,6 +158,14 @@ function extend (defaultOptions = {}) {
|
|
|
157
158
|
opts.json = jsonShortcut
|
|
158
159
|
return rock(opts, body, cb)
|
|
159
160
|
}
|
|
161
|
+
rock.promises[method] = (opts, body) => {
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
rock[method](opts, body, (err, response, data) => {
|
|
164
|
+
if (err) return reject(err)
|
|
165
|
+
resolve({ response, data })
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
}
|
|
160
169
|
})
|
|
161
170
|
rock.concat = rock
|
|
162
171
|
rock.defaults = _default
|
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rock-req",
|
|
3
3
|
"description": "Ultra-light (150 LOC, No dependencies) & Ultra-fast request library with reliable retry on failure, http/https, redirects, gzip/deflate/brotli, extensible, proxy, streams, JSON mode, forms, timeout",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.2.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "David Grelaud & Feross Aboukhadijeh"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"
|
|
10
|
-
"standard": "*",
|
|
9
|
+
"standard": "17.1.2",
|
|
11
10
|
"string-to-stream": "3.0.1",
|
|
12
|
-
"tape": "5.
|
|
11
|
+
"tape": "5.9.0"
|
|
13
12
|
},
|
|
14
13
|
"engines": {
|
|
15
14
|
"node": ">=16"
|
|
@@ -37,6 +36,9 @@
|
|
|
37
36
|
],
|
|
38
37
|
"license": "MIT",
|
|
39
38
|
"main": "index.js",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": "./index.js"
|
|
41
|
+
},
|
|
40
42
|
"repository": {
|
|
41
43
|
"type": "git",
|
|
42
44
|
"url": "git://github.com/carboneio/rock-req.git"
|