@firekid/hurl 1.0.6 → 1.0.7
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 +61 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ https://github.com/Firekid-is-him/hurl
|
|
|
12
12
|
|
|
13
13
|
## Purpose
|
|
14
14
|
|
|
15
|
-
`hurl` solves the problems that `request` left behind when it was deprecated and that `axios` never fully addressed: no edge runtime support, a 35KB bundle, no built-in retry logic, no request deduplication, and no upload progress tracking. `hurl` ships all of these in under
|
|
15
|
+
`hurl` solves the problems that `request` left behind when it was deprecated and that `axios` never fully addressed: no edge runtime support, a 35KB bundle, no built-in retry logic, no request deduplication, and no upload progress tracking. `hurl` ships all of these in under 10KB with zero runtime dependencies.
|
|
16
16
|
|
|
17
17
|
## Core Concepts
|
|
18
18
|
|
|
@@ -93,6 +93,7 @@ type HurlRequestOptions = {
|
|
|
93
93
|
onUploadProgress?: ProgressCallback
|
|
94
94
|
onDownloadProgress?: ProgressCallback
|
|
95
95
|
stream?: boolean
|
|
96
|
+
throwOnError?: boolean
|
|
96
97
|
debug?: boolean
|
|
97
98
|
requestId?: string
|
|
98
99
|
deduplicate?: boolean
|
|
@@ -219,6 +220,17 @@ await hurl.get('/users', {
|
|
|
219
220
|
})
|
|
220
221
|
```
|
|
221
222
|
|
|
223
|
+
```ts
|
|
224
|
+
import { clearCache, invalidateCache } from '@firekid/hurl'
|
|
225
|
+
|
|
226
|
+
// Clear the entire cache
|
|
227
|
+
clearCache()
|
|
228
|
+
|
|
229
|
+
// Invalidate a single entry by URL or custom key
|
|
230
|
+
invalidateCache('https://api.example.com/users')
|
|
231
|
+
invalidateCache('all-users') // if you used a custom cache key
|
|
232
|
+
```
|
|
233
|
+
|
|
222
234
|
## Request Deduplication
|
|
223
235
|
|
|
224
236
|
When `deduplicate` is true and the same GET URL is called multiple times simultaneously, only one network request is made.
|
|
@@ -232,19 +244,35 @@ const [a, b] = await Promise.all([
|
|
|
232
244
|
|
|
233
245
|
## Proxy
|
|
234
246
|
|
|
247
|
+
Native fetch does not support programmatic proxy configuration out of the box. Proxy support depends on your Node.js version:
|
|
248
|
+
|
|
249
|
+
**Node.js 18** — install `undici@6` (v7 dropped Node 18 support), use `ProxyAgent`:
|
|
235
250
|
```ts
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
251
|
+
// npm install undici@6
|
|
252
|
+
import { ProxyAgent, setGlobalDispatcher } from 'undici'
|
|
253
|
+
setGlobalDispatcher(new ProxyAgent('http://proxy.example.com:8080'))
|
|
254
|
+
```
|
|
239
255
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
})
|
|
256
|
+
**Node.js 20** — `undici` is bundled with `ProxyAgent` support:
|
|
257
|
+
```ts
|
|
258
|
+
import { ProxyAgent, setGlobalDispatcher } from 'undici'
|
|
259
|
+
setGlobalDispatcher(new ProxyAgent('http://proxy.example.com:8080'))
|
|
246
260
|
```
|
|
247
261
|
|
|
262
|
+
**Node.js 22.3+** — supports `EnvHttpProxyAgent` which reads `HTTP_PROXY`/`HTTPS_PROXY` env vars automatically:
|
|
263
|
+
```ts
|
|
264
|
+
import { EnvHttpProxyAgent, setGlobalDispatcher } from 'undici'
|
|
265
|
+
setGlobalDispatcher(new EnvHttpProxyAgent())
|
|
266
|
+
// now set HTTP_PROXY=http://proxy.example.com:8080 in your env
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**Node.js 24+** — native fetch respects env vars when `NODE_USE_ENV_PROXY=1` is set:
|
|
270
|
+
```bash
|
|
271
|
+
NODE_USE_ENV_PROXY=1 HTTP_PROXY=http://proxy.example.com:8080 node app.js
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
The `proxy` option in `HurlRequestOptions` is reserved for a future release where this will be handled automatically.
|
|
275
|
+
|
|
248
276
|
## Parallel Requests
|
|
249
277
|
|
|
250
278
|
```ts
|
|
@@ -271,6 +299,8 @@ const adminApi = api.extend({
|
|
|
271
299
|
})
|
|
272
300
|
```
|
|
273
301
|
|
|
302
|
+
`create()` produces a fully isolated instance — no shared defaults, interceptors, or state with the parent. `extend()` merges the provided defaults on top of the parent's and inherits all of the parent's interceptors.
|
|
303
|
+
|
|
274
304
|
## Debug Mode
|
|
275
305
|
|
|
276
306
|
Logs the full request (method, url, headers, body, query, timeout, retry config) and response (status, timing, headers, data) to the console. Errors and retries are also logged.
|
|
@@ -283,6 +313,15 @@ await hurl.get('/users', { debug: true })
|
|
|
283
313
|
|
|
284
314
|
`hurl` throws a `HurlError` on HTTP errors (4xx, 5xx), network failures, timeouts, aborts, and parse failures. It never resolves silently on bad status codes.
|
|
285
315
|
|
|
316
|
+
If you want to handle 4xx/5xx responses without a try/catch, set `throwOnError: false` — the response resolves normally and you can check `res.status` yourself.
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
const res = await hurl.get('/users', { throwOnError: false })
|
|
320
|
+
if (res.status === 404) {
|
|
321
|
+
console.log('not found')
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
286
325
|
```ts
|
|
287
326
|
import hurl, { HurlError } from '@firekid/hurl'
|
|
288
327
|
|
|
@@ -373,10 +412,10 @@ Sends a request with the method specified in options. Defaults to GET. Returns `
|
|
|
373
412
|
Runs an array of requests in parallel. Returns a promise that resolves when all requests complete. Equivalent to `Promise.all`.
|
|
374
413
|
|
|
375
414
|
### hurl.create(defaults?)
|
|
376
|
-
Creates a new isolated instance with its own defaults, interceptors, and state. Does not
|
|
415
|
+
Creates a new isolated instance with its own defaults, interceptors, and state. Does not inherit anything from the parent instance.
|
|
377
416
|
|
|
378
417
|
### hurl.extend(defaults?)
|
|
379
|
-
Creates a new instance that inherits the current defaults
|
|
418
|
+
Creates a new instance that inherits the current defaults, merges in the provided ones, and copies all parent interceptors (request, response, and error).
|
|
380
419
|
|
|
381
420
|
### hurl.defaults.set(defaults)
|
|
382
421
|
Sets global defaults for the current instance. Merged into every request.
|
|
@@ -404,6 +443,15 @@ import { clearCache } from '@firekid/hurl'
|
|
|
404
443
|
clearCache()
|
|
405
444
|
```
|
|
406
445
|
|
|
446
|
+
### invalidateCache(key)
|
|
447
|
+
Removes a single entry from the in-memory cache by URL or custom cache key.
|
|
448
|
+
|
|
449
|
+
```ts
|
|
450
|
+
import { invalidateCache } from '@firekid/hurl'
|
|
451
|
+
invalidateCache('https://api.example.com/users')
|
|
452
|
+
invalidateCache('all-users') // if you used a custom cache key
|
|
453
|
+
```
|
|
454
|
+
|
|
407
455
|
## License
|
|
408
456
|
|
|
409
|
-
MIT
|
|
457
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firekid/hurl",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Zero-dependency HTTP client for Node.js and edge runtimes. Built on fetch. The modern replacement for axios, request, got, node-fetch, and ky. Works on Cloudflare Workers, Vercel Edge, Deno, and Bun.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|