You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/api/globals.md
+9-13Lines changed: 9 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -588,27 +588,21 @@ Node.js implements the [WHATWG Fetch Standard][] with intentional differences to
588
588
##### Async iterable request bodies
589
589
590
590
Node.js supports async iterables as request bodies—a behavior not included in the Fetch Standard.
591
-
```js
591
+
```mjs
592
592
constdata= {
593
593
async*[Symbol.asyncIterator]() {
594
594
yield'hello';
595
595
yield'world';
596
-
}
596
+
},
597
597
};
598
-
599
-
awaitfetch('https://example.com', {
600
-
method:'POST',
601
-
body: data,
602
-
duplex:'half'
603
-
});
604
598
```
605
599
606
600
When using an async iterable or a `ReadableStream` as the request body, the `duplex` option must be set to `'half'`.
607
601
608
602
##### FormData with stream-backed Blob objects
609
603
610
604
`FormData` entries may include stream-backed `Blob` objects created from the filesystem, enabling efficient uploads of large files without buffering them in memory.
The `Response` constructor accepts async iterables, allowing flexible construction of streaming responses in server environments.
626
-
```js
620
+
```mjs
627
621
constres=newResponse(asyncIterable);
628
622
```
629
623
@@ -646,15 +640,15 @@ When using `redirect: 'manual'`, Node.js returns the actual redirect response ra
646
640
In Node.js, unconsumed response bodies may delay the release of underlying network resources. This can reduce connection reuse or cause stalls under load.
647
641
648
642
Always consume or cancel the response body:
649
-
```js
643
+
```mjs
650
644
constres=awaitfetch(url);
651
645
forawait (constchunkofres.body) {
652
646
// process chunk
653
647
}
654
648
```
655
649
656
650
For header-only requests, prefer `HEAD` to avoid creating a body:
0 commit comments