rock-req 5.1.3 → 5.2.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.
Files changed (3) hide show
  1. package/README.md +38 -17
  2. package/index.js +10 -1
  3. 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 (2023):
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,30 +52,50 @@ 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 by-default" and "false-light" HTTP request libraries!
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 | LOC (2025/2023) |
61
+ |--------------|-----------:|------------:|---------:|-----------:|----------------:|
62
+ | rock-req 🙋‍♂️ | 26842 ops | 26782 ops | 26179 ops | 21229 ops | 152 (+5%) |
63
+ | simple-get | 26532 ops | 26802 ops | 25954 ops | 21187 ops | 317 (+0%) |
64
+ | axios | 4110 ops | 3999 ops | 3996 ops | 14788 ops | 19883 (+42%) |
65
+ | got | 14786 ops | 15234 ops | 15149 ops | 15287 ops | 16904 (+83%) |
66
+ | fetch | 15676 ops | 16252 ops | 15784 ops | 27675 ops | 54211 (+306%) |
67
+ | request | 17102 ops | 14586 ops | 14346 ops | 18202 ops | 58057 (+24%) |
68
+ | superagent | 3862 ops | 3979 ops | 3889 ops | 19271 ops | 31913 (+98%) |
69
+ | phin | 15549 ops | 14160 ops | 13915 ops | 15430 ops | 20064 (+5960%) |
70
+ | _undici_* | 32480 ops | 33272 ops | 32738 ops | 25961 ops | 23235 (+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. |
58
77
  | ------------ |--------------:|--------------:| --------------:| --------------:|
59
- | rock-req 🙋‍♂️ | 22816 req/s | 21797 req/s | 21964 req/s | 144 LOC |
60
- | simple-get | 2937 req/s | 3260 req/s | 21258 req/s | 317 LOC |
61
- | axios | 5090 req/s | 4910 req/s | 3196 req/s | 13983 LOC |
62
- | got | 2163 req/s | 1762 req/s | 9961 req/s | 9227 LOC |
63
- | fetch | 2101 req/s | 2102 req/s | 2020 req/s | 13334 LOC |
64
- | request | 2249 req/s | 1869 req/s | 15815 req/s | 46572 LOC |
65
- | superagent | 2776 req/s | 2100 req/s | 2895 req/s | 16109 LOC |
66
- | phin | 3178 req/s | 1164 req/s | 21299 req/s | 331 LOC |
67
- | _undici_* | 24095 req/s | 24378 req/s | 24191 req/s | 16225 LOC |
78
+ | rock-req 🙋‍♂️ | 22816 ops | 21797 ops | 21964 ops | 144 LOC |
79
+ | simple-get | 2937 ops | 3260 ops | 21258 ops | 317 LOC |
80
+ | axios | 5090 ops | 4910 ops | 3196 ops | 13983 LOC |
81
+ | got | 2163 ops | 1762 ops | 9961 ops | 9227 LOC |
82
+ | fetch | 2101 ops | 2102 ops | 2020 ops | 13334 LOC |
83
+ | request | 2249 ops | 1869 ops | 15815 ops | 46572 LOC |
84
+ | superagent | 2776 ops | 2100 ops | 2895 ops | 16109 LOC |
85
+ | phin | 3178 ops | 1164 ops | 21299 ops | 331 LOC |
86
+ | _undici_* | 24095 ops | 24378 ops | 24191 ops | 16225 LOC |
68
87
 
69
88
 
70
- > NodeJS 20 activates HTTP keep-alive by default, like `rock-req`
89
+ > `LOC` = Lines of Code, including dependencies (excluding dev dependencies)
90
+ > `ops` = request per second
71
91
 
72
- > `undici` is a low-level API, faster alternative to the native NodeJS http module. It is the glass ceiling limit for NodeJS.
92
+ > 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
93
 
74
- > `rock-req` uses only the native NodeJS http module and provides many high-level features, a lot more than `phin` and `simple-get` with fewer lines of code.
94
+ > `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
95
 
76
- > Tested on Macbook Pro M1 Max
96
+ > `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
97
 
98
+ > Interestingly, the differences are less visible on Bun.sh.
78
99
 
79
100
  ## Install
80
101
 
@@ -92,7 +113,7 @@ This packaged in maintained by Carbone:
92
113
 
93
114
  <p>
94
115
  <a href="https://carbone.io" alt="Carbone.io - Efficient PDF / DOCX / XLSX / CSV / HTML / XML generator with templates and JSON">
95
- <img src="https://raw.githubusercontent.com/carboneio/rock-req/master/doc/carbone-logo.svg" alt="Carbone.io logo" height="60"/>
116
+ <img src="https://carbone.io/img/carbone-logo.svg" alt="Carbone.io logo" height="60"/>
96
117
  </a>
97
118
  </p>
98
119
 
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.1.3",
4
+ "version": "5.2.1",
5
5
  "author": {
6
6
  "name": "David Grelaud & Feross Aboukhadijeh"
7
7
  },
8
8
  "devDependencies": {
9
- "self-signed-https": "1.0.5",
10
- "standard": "*",
9
+ "standard": "17.1.2",
11
10
  "string-to-stream": "3.0.1",
12
- "tape": "5.6.3"
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"