@npora/request 1.7.0 → 1.9.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 +30 -2
- package/dist/index.cjs +2941 -3489
- package/dist/index.d.cts +726 -652
- package/dist/index.d.ts +726 -652
- package/dist/index.js +2925 -3447
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -16,8 +16,9 @@ pnpm add @npora/request
|
|
|
16
16
|
npm install @npora/request
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
Node.js 22 or newer is required. Modern Chromium
|
|
20
|
-
Workers are supported through their native Fetch
|
|
19
|
+
Node.js 22 or newer is required. Modern Chromium-based browsers, Firefox,
|
|
20
|
+
Safari/WebKit, and Web Workers are supported through their native Fetch
|
|
21
|
+
implementations.
|
|
21
22
|
|
|
22
23
|
## Quick start
|
|
23
24
|
|
|
@@ -52,6 +53,32 @@ console.log(response.headers)
|
|
|
52
53
|
console.log(response.raw)
|
|
53
54
|
```
|
|
54
55
|
|
|
56
|
+
## Streaming responses
|
|
57
|
+
|
|
58
|
+
SSE and NDJSON responses are decoded incrementally as async iterables. The
|
|
59
|
+
client also detects `text/event-stream` and common NDJSON content types
|
|
60
|
+
automatically:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import type { ServerSentEvent } from '@npora/request'
|
|
64
|
+
|
|
65
|
+
const events = await api.sse('/events')
|
|
66
|
+
|
|
67
|
+
for await (const event of events) {
|
|
68
|
+
console.log(event.event, event.data, event.id)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const records = await api.ndjson<User>('/users/export')
|
|
72
|
+
|
|
73
|
+
for await (const user of records) {
|
|
74
|
+
console.log(user.name)
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Iteration is lazy and does not buffer the complete response. Breaking out of
|
|
79
|
+
the loop cancels the response reader. `maxResponseSize` remains enforced while
|
|
80
|
+
the stream is consumed.
|
|
81
|
+
|
|
55
82
|
## Request configuration
|
|
56
83
|
|
|
57
84
|
```ts
|
|
@@ -287,6 +314,7 @@ Stable request error codes:
|
|
|
287
314
|
- `TIMEOUT_ERROR`
|
|
288
315
|
- `ABORT_ERROR`
|
|
289
316
|
- `PARSER_ERROR`
|
|
317
|
+
- `RESPONSE_TOO_LARGE`
|
|
290
318
|
- `CIRCUIT_OPEN`
|
|
291
319
|
- `CONCURRENCY_LIMIT`
|
|
292
320
|
|