hyperttp 0.4.1 → 0.4.4
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/Hyperttp/Client/HyperClient.d.ts +146 -104
- package/Hyperttp/Client/HyperClient.d.ts.map +1 -1
- package/Hyperttp/Client/HyperClient.js +257 -193
- package/Hyperttp/Client/HyperClient.js.map +1 -1
- package/Hyperttp/Request.d.ts +20 -3
- package/Hyperttp/Request.d.ts.map +1 -1
- package/Hyperttp/Request.js +24 -4
- package/Hyperttp/Request.js.map +1 -1
- package/Hyperttp/UrlExtractor.d.ts.map +1 -1
- package/Hyperttp/UrlExtractor.js.map +1 -1
- package/Hyperttp/Utils/RequestBuilder.d.ts +30 -8
- package/Hyperttp/Utils/RequestBuilder.d.ts.map +1 -1
- package/Hyperttp/Utils/RequestBuilder.js +62 -21
- package/Hyperttp/Utils/RequestBuilder.js.map +1 -1
- package/README.md +294 -125
- package/package.json +23 -24
package/README.md
CHANGED
|
@@ -1,200 +1,369 @@
|
|
|
1
|
-
# Hyperttp
|
|
1
|
+
# Hyperttp ⚡
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
automatic retries, cookie management, and automatic JSON/XML parsing.
|
|
3
|
+
> English | [Русский](https://github.com/Dirold2/hyperttp/tree/main/lang/ru)
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/hyperttp)
|
|
6
|
+
[](https://www.npmjs.com/package/hyperttp)
|
|
7
|
+
[](./LICENSE)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 🌐 Language
|
|
13
|
+
|
|
14
|
+
- 🇺🇸 English
|
|
15
|
+
- 🇷🇺 [Русский](https://github.com/Dirold2/hyperttp/tree/main/lang/ru)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 🔗 Quick Links
|
|
20
|
+
|
|
21
|
+
- 🏢 **Organization:** [github.com/IT-IF-OR](https://github.com/IT-IF-OR)
|
|
22
|
+
- 👤 **Author:** [github.com/dirold2](https://github.com/dirold2)
|
|
23
|
+
- 📦 **npm:** [npmjs.com/org/hyperttp](https://www.npmjs.com/org/hyperttp)
|
|
24
|
+
- ⚙️ **Core engine:** [`@hyperttp/core`](https://www.npmjs.com/package/@hyperttp/core)
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
**Hyperttp** is a batteries-included, high-performance HTTP client for Node.js, Bun, Deno, and Browser environments.
|
|
29
|
+
It is a feature-rich, production-ready extension over the optimized [`@hyperttp/core`](https://www.npmjs.com/package/@hyperttp/core) engine,
|
|
30
|
+
shipping with caching, rate limiting, request queuing, inflight deduplication, performance metrics, and a fluent chainable API — all pre-wired and ready to use.
|
|
17
31
|
|
|
18
|
-
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🔥 Key Features
|
|
35
|
+
|
|
36
|
+
- **🎯 Smart Response Parsing:** Automatically parses responses based on `responseType` (`json`, `text`, `xml`, `html`, `buffer`, `blob`, `stream`).
|
|
37
|
+
- **🔀 Concurrency Management:** Built-in queue plugin (`withQueue`) to strictly enforce concurrent request limits.
|
|
38
|
+
- **💾 Smart LRU Caching:** Dedicated caching layer (`withCache`) with TTL support to prevent redundant network drift.
|
|
39
|
+
- **🚦 Rate Limiting:** Built-in Token Bucket algorithm to protect against external API blocks and rate limits.
|
|
40
|
+
- **🛡️ Inflight Deduplication:** Prevents duplicate simultaneous requests to the same endpoint if the first is pending.
|
|
41
|
+
- **📈 Real-Time Metrics:** Out-of-the-box telemetry tracking latencies, RPS, cache hits, and overall client health.
|
|
42
|
+
- **🔌 Modular Architecture:** Clean pipeline approach allowing custom plugins, serialization layers, and interceptors.
|
|
43
|
+
- **💎 Fluent Request Builder API:** Clean, chainable API syntax to compose and configure requests with ease.
|
|
44
|
+
- **🗜️ Transparent Decompression:** Automatic handling of `gzip`, `deflate`, and `br` (Brotli) out of the box.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 📦 Ecosystem Packages
|
|
49
|
+
|
|
50
|
+
| Package | Description | Repository |
|
|
51
|
+
| ---------------------------------------------------------------------------------------- | -------------------------------------------- | --------------------------------------------------------------- |
|
|
52
|
+
| **`hyperttp`** (you are here) | High-level client with all plugins pre-wired | [GitHub](https://github.com/dirold2/hyperttp) |
|
|
53
|
+
| [`@hyperttp/core`](https://www.npmjs.com/package/@hyperttp/core) | Low-level core with transport pipeline | [GitHub](https://github.com/IT-IF-OR/hyperttp-core) |
|
|
54
|
+
| [`@hyperttp/types`](https://www.npmjs.com/package/@hyperttp/types) | Shared TypeScript type definitions | [GitHub](https://github.com/dirold2/hyperttp-types) |
|
|
55
|
+
| [`@hyperttp/transport-bun`](https://www.npmjs.com/package/@hyperttp/transport-bun) | Native Bun transport | [GitHub](https://github.com/IT-IF-OR/hyperttp-transport-bun) |
|
|
56
|
+
| [`@hyperttp/transport-undici`](https://www.npmjs.com/package/@hyperttp/transport-undici) | Undici transport for Node.js | [GitHub](https://github.com/IT-IF-OR/hyperttp-transport-undici) |
|
|
57
|
+
| [`@hyperttp/parser`](https://www.npmjs.com/package/@hyperttp/parser) | Response body parser (JSON/XML/HTML) | [GitHub](https://github.com/IT-IF-OR/hyperttp-parser) |
|
|
58
|
+
| [`@hyperttp/serializer`](https://www.npmjs.com/package/@hyperttp/serializer) | Request body serializer | [GitHub](https://github.com/IT-IF-OR/hyperttp-serializer) |
|
|
59
|
+
| [`@hyperttp/cache`](https://www.npmjs.com/package/@hyperttp/cache) | HTTP response caching | [GitHub](https://github.com/IT-IF-OR/hyperttp-cache) |
|
|
60
|
+
| [`@hyperttp/queue`](https://www.npmjs.com/package/@hyperttp/queue) | Request queueing | [GitHub](https://github.com/IT-IF-OR/hyperttp-queue) |
|
|
61
|
+
| [`@hyperttp/ratelimit`](https://www.npmjs.com/package/@hyperttp/ratelimit) | Rate limiting | [GitHub](https://github.com/IT-IF-OR/hyperttp-ratelimit) |
|
|
62
|
+
| [`@hyperttp/inflight`](https://www.npmjs.com/package/@hyperttp/inflight) | In-flight request deduplication | [GitHub](https://github.com/IT-IF-OR/hyperttp-inflight) |
|
|
63
|
+
| [`@hyperttp/interceptors`](https://www.npmjs.com/package/@hyperttp/interceptors) | Request/response interceptors | [GitHub](https://github.com/IT-IF-OR/hyperttp-interceptors) |
|
|
64
|
+
| [`@hyperttp/metrics`](https://www.npmjs.com/package/@hyperttp/metrics) | Performance metrics | [GitHub](https://github.com/IT-IF-OR/hyperttp-metrics) |
|
|
65
|
+
|
|
66
|
+
### Which package should I use?
|
|
67
|
+
|
|
68
|
+
- **Just need HTTP requests with caching, retries, and parsing?** → Use `hyperttp` (this package)
|
|
69
|
+
- **Need full control over the pipeline?** → Use `@hyperttp/core`
|
|
70
|
+
- **Building a custom transport or plugin?** → Use `@hyperttp/types`
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🚀 Installation
|
|
19
75
|
|
|
20
76
|
```bash
|
|
21
77
|
npm install hyperttp
|
|
78
|
+
|
|
79
|
+
# Optional: install a specific transport
|
|
80
|
+
npm install @hyperttp/transport-bun # for Bun
|
|
81
|
+
npm install @hyperttp/transport-undici # for Node.js
|
|
22
82
|
```
|
|
23
83
|
|
|
24
84
|
---
|
|
25
85
|
|
|
26
|
-
##
|
|
86
|
+
## 📦 Quick Start
|
|
27
87
|
|
|
28
|
-
|
|
88
|
+
Simply import `HyperClient` and start dispatching requests. Core features like caching, queue management,
|
|
89
|
+
and rate limiting are instantly preconfigured and active out of the box.
|
|
29
90
|
|
|
30
91
|
```typescript
|
|
31
|
-
import
|
|
92
|
+
import { HyperClient } from "hyperttp";
|
|
32
93
|
|
|
33
|
-
const client = new
|
|
94
|
+
const client = new HyperClient();
|
|
34
95
|
|
|
35
|
-
// Simple GET request
|
|
36
|
-
const data = await client.get("https://api.example.com/data");
|
|
96
|
+
// Simple GET request (instantly resolves to the pre-parsed type-safe body)
|
|
97
|
+
const data = await client.get<MyDataType>("https://api.example.com/data");
|
|
37
98
|
|
|
38
|
-
// POST request
|
|
39
|
-
const
|
|
40
|
-
name: "Item
|
|
99
|
+
// POST request specifying expected response type alongside body payload
|
|
100
|
+
const newItem = await client.post<Item>("https://api.example.com/items", "json", {
|
|
101
|
+
name: "New Item Structure",
|
|
41
102
|
});
|
|
103
|
+
|
|
104
|
+
// Explicit response type
|
|
105
|
+
const html = await client.get<string>("https://example.com", "text");
|
|
106
|
+
const xml = await client.get<XmlDoc>("https://api.example.com/feed.xml", "xml");
|
|
107
|
+
|
|
108
|
+
// Streaming responses (e.g., LLM completions)
|
|
109
|
+
const chatStream = await client.stream("https://api.openai.com/v1/chat/completions");
|
|
110
|
+
const reader = chatStream.body.getReader();
|
|
42
111
|
```
|
|
43
112
|
|
|
44
|
-
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 💎 Fluent Builder API
|
|
116
|
+
|
|
117
|
+
Invoke the `.request(url)` chain to programmatically craft highly specific request structures on the fly:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const user = await client
|
|
121
|
+
.request("https://api.example.com/users")
|
|
122
|
+
.post() // Specify HTTP Method (Defaults to GET)
|
|
123
|
+
.query({ include: "profile" }) // Safely append and encode Query Parameters
|
|
124
|
+
.headers({ "X-Request-ID": crypto.randomUUID() })
|
|
125
|
+
.jsonBody({ name: "John", email: "john@example.com" }) // Automatically serializes and sets Content-Type header
|
|
126
|
+
.json<User>() // Asserts expected response format (.text(), .buffer(), .stream())
|
|
127
|
+
.timeout(5000) // Instantiates a contextual, request-scoped AbortSignal timeout
|
|
128
|
+
.send();
|
|
129
|
+
```
|
|
45
130
|
|
|
46
131
|
---
|
|
47
132
|
|
|
48
133
|
## ⚙️ Advanced Configuration
|
|
49
134
|
|
|
50
|
-
|
|
135
|
+
Fine-tune every infrastructure layer by supplying a configuration object directly to the `HyperClient` constructor:
|
|
51
136
|
|
|
52
137
|
```typescript
|
|
53
|
-
import
|
|
138
|
+
import { HyperClient } from "hyperttp";
|
|
54
139
|
|
|
55
|
-
const client = new
|
|
56
|
-
// 🌐 Network
|
|
140
|
+
const client = new HyperClient({
|
|
141
|
+
// 🌐 Core Network Level Settings (NetworkOptions)
|
|
57
142
|
network: {
|
|
58
|
-
timeout: 10000, // Request timeout
|
|
59
|
-
maxConcurrent: 50, //
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
143
|
+
timeout: 10000, // Request timeout in milliseconds
|
|
144
|
+
maxConcurrent: 50, // Maximum simultaneous active sockets (0 = unlimited)
|
|
145
|
+
pipelining: 1, // Pipelined requests per connection limit
|
|
146
|
+
keepAliveTimeout: 30000, // Keep-alive socket preservation time in ms
|
|
147
|
+
rejectUnauthorized: true, // Reject untrusted or self-signed SSL certificates
|
|
148
|
+
followRedirects: true, // Automatically follow HTTP redirects
|
|
149
|
+
maxRedirects: 5, // Maximum follow threshold for redirects
|
|
150
|
+
maxResponseBytes: 10 * 1024 * 1024, // Prevents OOM by capping response body size (10 MB)
|
|
151
|
+
userAgent: "HyperClient/2.0", // Global fallback User-Agent header
|
|
152
|
+
headers: {
|
|
153
|
+
// Default baseline headers appended to every request
|
|
154
|
+
"X-App-Client": "Backend",
|
|
155
|
+
},
|
|
156
|
+
validateStatus: (status) => status >= 200 && status < 300, // Status success validation rules
|
|
67
157
|
},
|
|
68
158
|
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
159
|
+
// 🔄 Automated Retry Logic (RetryOptions)
|
|
160
|
+
retry: {
|
|
161
|
+
maxRetries: 3, // Number of recovery attempts before failing
|
|
162
|
+
baseDelay: 1000, // Initial delay baseline between retries (ms)
|
|
163
|
+
maxDelay: 10000, // Maximum cap for retry delay intervals (ms)
|
|
164
|
+
retryStatusCodes: [408, 429, 502, 503, 504], // Target status codes that trigger a retry
|
|
165
|
+
jitter: true, // Randomized delay variations to avoid thundering herd crashes
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
// 📈 Telemetry and Engine Logging
|
|
169
|
+
trackMetrics: true, // Enables global system performance collection
|
|
170
|
+
verbose: false, // Toggles internal micro-logs output
|
|
171
|
+
logger: (level, message, meta) => {
|
|
172
|
+
// Custom logging implementation sink
|
|
173
|
+
console.log(`[${level}] ${message}`, meta ?? "");
|
|
74
174
|
},
|
|
75
175
|
|
|
76
|
-
//
|
|
176
|
+
// 💾 Extended Plugin Configurations (Injected via HyperttpPluginsExtension)
|
|
177
|
+
cache: {
|
|
178
|
+
enabled: true,
|
|
179
|
+
ttl: 300000, // 5 minutes cache lifespan
|
|
180
|
+
maxSize: 500, // Max item limit for local LRU storage
|
|
181
|
+
},
|
|
77
182
|
rateLimit: {
|
|
78
|
-
enabled: true,
|
|
79
|
-
maxRequests: 100,
|
|
80
|
-
windowMs: 60000,
|
|
183
|
+
enabled: true,
|
|
184
|
+
maxRequests: 100,
|
|
185
|
+
windowMs: 60000,
|
|
81
186
|
},
|
|
187
|
+
inflight: {
|
|
188
|
+
enabled: true,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
```
|
|
82
192
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## 🔌 Pre-Wired Plugins
|
|
196
|
+
|
|
197
|
+
When using `HyperClient`, the following plugins are automatically registered:
|
|
198
|
+
|
|
199
|
+
| Plugin | Purpose |
|
|
200
|
+
| ------------------ | ----------------------------------------------------------- |
|
|
201
|
+
| `withSerializer` | Serializes request bodies (JSON, FormData, URLSearchParams) |
|
|
202
|
+
| `withParser` | Parses response bodies based on `responseType` |
|
|
203
|
+
| `withQueue` | Queues requests when concurrency limit is reached |
|
|
204
|
+
| `withRateLimit` | Enforces rate limits |
|
|
205
|
+
| `withInflight` | Deduplicates in-flight requests |
|
|
206
|
+
| `withCache` | Caches responses based on HTTP headers |
|
|
207
|
+
| `withInterceptors` | Request/response interceptors |
|
|
208
|
+
| `withMetrics` | Collects performance metrics |
|
|
209
|
+
|
|
210
|
+
### Custom Plugins
|
|
211
|
+
|
|
212
|
+
Extend the client with your own hooks:
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
client.use({
|
|
216
|
+
name: "performance-logger",
|
|
217
|
+
priority: 100, // Sorted execution priority (higher runs first)
|
|
218
|
+
mode: "background", // Forces onResponse to run as a non-blocking side-effect
|
|
219
|
+
|
|
220
|
+
setup: (ctx) => {
|
|
221
|
+
ctx.config.logger?.info?.("Plugin active");
|
|
86
222
|
},
|
|
87
223
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
maxRetries: 3, // Max retry attempts
|
|
91
|
-
baseDelay: 1000, // Base delay between retries (ms)
|
|
92
|
-
maxDelay: 10000, // Max delay (ms)
|
|
93
|
-
jitter: true, // Add randomization to delays
|
|
94
|
-
retryStatusCodes: [408, 429, 500, 502, 503, 504],
|
|
224
|
+
onRequest: async (req, ctx) => {
|
|
225
|
+
req.meta.startTime = performance.now();
|
|
95
226
|
},
|
|
96
227
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
maxHistory: 1000, // Metrics history size
|
|
228
|
+
onResponse: async (res, req, ctx) => {
|
|
229
|
+
const duration = performance.now() - (req.meta.startTime as number);
|
|
230
|
+
console.log(`[${req.method}] ${req.url} -> ${res.status} (${duration.toFixed(2)}ms)`);
|
|
101
231
|
},
|
|
102
232
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
233
|
+
onError: async (error, req, ctx) => {
|
|
234
|
+
console.error(`Request failed to ${req.url}: ${error.message}`);
|
|
235
|
+
// Return a response object here to bypass/recover from the failure
|
|
236
|
+
},
|
|
106
237
|
});
|
|
107
238
|
```
|
|
108
239
|
|
|
109
|
-
###
|
|
240
|
+
### Plugin Phases
|
|
110
241
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
.json()
|
|
118
|
-
.send();
|
|
119
|
-
|
|
120
|
-
// Get client statistics
|
|
121
|
-
const stats = client.getStats();
|
|
122
|
-
console.log({
|
|
123
|
-
cacheSize: stats.cacheSize, // Current cache size
|
|
124
|
-
inflightRequests: stats.inflightRequests, // Active requests
|
|
125
|
-
queuedRequests: stats.queuedRequests, // Requests waiting in queue
|
|
126
|
-
activeRequests: stats.activeRequests, // Currently executing
|
|
127
|
-
currentRateLimit: stats.currentRateLimit, // Used rate limit slots
|
|
128
|
-
});
|
|
242
|
+
| Phase | Hook | Description |
|
|
243
|
+
| ----------- | ---------------- | ------------------------------------------------------- |
|
|
244
|
+
| **REQUEST** | `onRequest` | Intercepts before execution. Supports short-circuiting. |
|
|
245
|
+
| **DATA** | `onResponseData` | Transforms raw transport responses before mapping. |
|
|
246
|
+
| **FORMAT** | `onResponse` | Modifies client-facing responses. |
|
|
247
|
+
| **ERROR** | `onError` | Catches and recovers from errors. |
|
|
129
248
|
|
|
130
|
-
|
|
131
|
-
const metrics = client.getMetrics("https://api.example.com/data");
|
|
132
|
-
console.log(metrics);
|
|
249
|
+
---
|
|
133
250
|
|
|
134
|
-
|
|
135
|
-
client.clearCache();
|
|
251
|
+
## 🏗️ Architecture Pipeline
|
|
136
252
|
|
|
137
|
-
|
|
138
|
-
client.clearMetrics();
|
|
253
|
+
`HyperClient` structures outbound and inbound requests across a sequential pipeline composed of granular plugins:
|
|
139
254
|
|
|
140
|
-
|
|
141
|
-
|
|
255
|
+
```
|
|
256
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
257
|
+
│ HyperClient │
|
|
258
|
+
│ (Auto-wires: Serializer → Parser → Queue → RateLimit → │
|
|
259
|
+
│ Inflight → Cache → Interceptors → Metrics) │
|
|
260
|
+
└──────────────────────────┬──────────────────────────────────────┘
|
|
261
|
+
│
|
|
262
|
+
▼
|
|
263
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
264
|
+
│ HyperCore │
|
|
265
|
+
│ │
|
|
266
|
+
│ 1. Request Pipeline (onRequest) ─── short-circuit capable │
|
|
267
|
+
│ │ │
|
|
268
|
+
│ 2. Transport Execution (HyperTransport) │
|
|
269
|
+
│ ├─ BunTransport (native Bun fetch) │
|
|
270
|
+
│ ├─ UndiciTransport (Node.js) │
|
|
271
|
+
│ └─ NodeTransport (global fetch) │
|
|
272
|
+
│ │ │
|
|
273
|
+
│ 3. Response Data Pipeline (onResponseData) │
|
|
274
|
+
│ │ │
|
|
275
|
+
│ 4. Internal Processing (decompression, mapping) │
|
|
276
|
+
│ │ │
|
|
277
|
+
│ 5. Response Pipeline (onResponse) │
|
|
278
|
+
│ ├─ Mutators (sync/async modification) │
|
|
279
|
+
│ └─ Side Effects (background, non-blocking) │
|
|
280
|
+
│ │ │
|
|
281
|
+
│ 6. Error Pipeline (onError) ─── recovery capable │
|
|
282
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
142
283
|
```
|
|
143
284
|
|
|
144
285
|
---
|
|
145
286
|
|
|
146
|
-
##
|
|
287
|
+
## 🛠️ Advanced Features
|
|
288
|
+
|
|
289
|
+
### Statistics, Cache, and Metrics Engine
|
|
147
290
|
|
|
148
291
|
```typescript
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
292
|
+
// Inspect pipeline internals (active connections, active queue payloads)
|
|
293
|
+
const stats = client.getStats();
|
|
294
|
+
console.log(stats);
|
|
295
|
+
|
|
296
|
+
// Retrieve aggregated historical latency and performance metrics
|
|
297
|
+
const allMetrics = client.getAllMetrics();
|
|
298
|
+
console.log(allMetrics);
|
|
299
|
+
|
|
300
|
+
// Flush the entire local response cache programmatically
|
|
301
|
+
await client.clearCache();
|
|
302
|
+
|
|
303
|
+
// Identify the execution context's current driving transport layout
|
|
304
|
+
const transportName = await client.getTransportName();
|
|
305
|
+
console.log(`Current Active Transport Driver: ${transportName}`);
|
|
306
|
+
|
|
307
|
+
// Gracefully teardown the client instance, draining keep-alive pools and sockets
|
|
308
|
+
await client.destroy();
|
|
157
309
|
```
|
|
158
310
|
|
|
159
|
-
|
|
311
|
+
### Stream Handlers
|
|
160
312
|
|
|
161
|
-
|
|
313
|
+
```typescript
|
|
314
|
+
// Returns an HttpResponse interface carrying a custom ReadableStream with clone() support
|
|
315
|
+
const streamResponse = await client.stream("https://stream.example.com/audio.mp3");
|
|
316
|
+
const reader = streamResponse.body.getReader();
|
|
317
|
+
```
|
|
162
318
|
|
|
163
|
-
###
|
|
319
|
+
### Extending Configuration
|
|
164
320
|
|
|
165
|
-
|
|
321
|
+
Create derived clients with merged configuration:
|
|
166
322
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
323
|
+
```typescript
|
|
324
|
+
const authenticatedClient = client.extend({
|
|
325
|
+
network: { headers: { Authorization: "Bearer token_abc" } },
|
|
326
|
+
});
|
|
327
|
+
```
|
|
170
328
|
|
|
171
|
-
|
|
329
|
+
---
|
|
172
330
|
|
|
173
|
-
|
|
331
|
+
## 🔄 Migration from axios
|
|
174
332
|
|
|
175
|
-
|
|
176
|
-
- FIFO processing of pending requests
|
|
177
|
-
- Methods: `enqueue()`, `activeCount`, `queuedCount`
|
|
333
|
+
If you're migrating from axios, Hyperttp provides a familiar API:
|
|
178
334
|
|
|
179
|
-
|
|
335
|
+
```typescript
|
|
336
|
+
// axios
|
|
337
|
+
import axios from "axios";
|
|
338
|
+
const { data } = await axios.get("/users/123");
|
|
339
|
+
|
|
340
|
+
// hyperttp (drop-in replacement)
|
|
341
|
+
import { HyperClient } from "hyperttp";
|
|
342
|
+
const client = new HyperClient();
|
|
343
|
+
const data = await client.get("/users/123");
|
|
344
|
+
```
|
|
180
345
|
|
|
181
|
-
|
|
346
|
+
---
|
|
182
347
|
|
|
183
|
-
|
|
184
|
-
- FIFO waiting when limit exceeded
|
|
185
|
-
- Methods: `wait()`, `tryConsume()`, `remainingRequests`
|
|
348
|
+
## 📊 Benchmarks
|
|
186
349
|
|
|
187
|
-
|
|
350
|
+
For detailed benchmarks across Bun and Node.js runtimes with various transports, see the [`@hyperttp/core` benchmarks](https://github.com/IT-IF-OR/hyperttp-core#-benchmarks).
|
|
188
351
|
|
|
189
|
-
|
|
352
|
+
**Key takeaways:**
|
|
190
353
|
|
|
191
|
-
-
|
|
192
|
-
-
|
|
193
|
-
-
|
|
194
|
-
-
|
|
354
|
+
- **Bun + BunTransport**: ~15.22K RPS with all plugins enabled
|
|
355
|
+
- **Node.js + UndiciTransport**: ~10.82K RPS with all plugins enabled
|
|
356
|
+
- **Plugin Overhead**: Only ~9-14% compared to the bare `@hyperttp/core`
|
|
357
|
+
- **Zero Error Rate**: 0% errors across all benchmark scenarios
|
|
195
358
|
|
|
196
359
|
---
|
|
197
360
|
|
|
198
|
-
##
|
|
361
|
+
## 📄 License
|
|
362
|
+
|
|
363
|
+
MIT
|
|
364
|
+
|
|
365
|
+
---
|
|
199
366
|
|
|
200
|
-
|
|
367
|
+
<p align="center">
|
|
368
|
+
<a href="https://github.com/dirold2">dirold2</a>
|
|
369
|
+
</p>
|
package/package.json
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyperttp",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "A high-performance, universal HTTP client for Node.js with caching, retries, queueing, rate limiting, cookies and logging.",
|
|
3
|
+
"version": "0.4.4",
|
|
4
|
+
"description": "A high-performance, universal HTTP client for Node.js, Bun, Deno and Browser with caching, retries, queueing, rate limiting, cookies and logging.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"main": "./index.js",
|
|
7
8
|
"types": "./index.d.ts",
|
|
8
|
-
"author": "dirold2",
|
|
9
|
-
"license": "MIT",
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/dirold2/hyperttp.git"
|
|
13
|
-
},
|
|
14
9
|
"exports": {
|
|
15
10
|
".": {
|
|
16
11
|
"types": "./index.d.ts",
|
|
17
|
-
"import": "./index.js"
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
"./package.json": "./package.json"
|
|
12
|
+
"import": "./index.js"
|
|
13
|
+
}
|
|
21
14
|
},
|
|
22
|
-
"sideEffects": [
|
|
23
|
-
"./index.js",
|
|
24
|
-
"./index.d.ts"
|
|
25
|
-
],
|
|
26
15
|
"keywords": [
|
|
27
16
|
"http",
|
|
28
17
|
"client",
|
|
@@ -33,19 +22,29 @@
|
|
|
33
22
|
"queue",
|
|
34
23
|
"retry",
|
|
35
24
|
"cookies",
|
|
36
|
-
"logger"
|
|
25
|
+
"logger",
|
|
26
|
+
"bun",
|
|
27
|
+
"deno",
|
|
28
|
+
"isomorphic",
|
|
29
|
+
"hyperttp"
|
|
37
30
|
],
|
|
31
|
+
"author": "dirold2",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/dirold2/hyperttp.git"
|
|
36
|
+
},
|
|
38
37
|
"dependencies": {
|
|
39
|
-
"@hyperttp/core": "^1.3.1",
|
|
40
|
-
"@hyperttp/types": "^0.2.0",
|
|
41
38
|
"@hyperttp/cache": "^1.1.6",
|
|
42
|
-
"@hyperttp/
|
|
43
|
-
"@hyperttp/inflight": "^1.1.
|
|
39
|
+
"@hyperttp/core": "^1.4.4",
|
|
40
|
+
"@hyperttp/inflight": "^1.1.6",
|
|
44
41
|
"@hyperttp/interceptors": "^1.1.5",
|
|
45
|
-
"@hyperttp/metrics": "^1.
|
|
42
|
+
"@hyperttp/metrics": "^1.2.0",
|
|
43
|
+
"@hyperttp/parser": "^1.1.8",
|
|
46
44
|
"@hyperttp/queue": "^1.1.5",
|
|
47
|
-
"@hyperttp/
|
|
48
|
-
"@hyperttp/
|
|
45
|
+
"@hyperttp/ratelimit": "^1.1.5",
|
|
46
|
+
"@hyperttp/serializer": "^1.2.0",
|
|
47
|
+
"@hyperttp/types": "^0.2.1"
|
|
49
48
|
},
|
|
50
49
|
"private": false
|
|
51
50
|
}
|