File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -516,6 +516,46 @@ changes:
516
516
517
517
A browser-compatible implementation of the [ ` fetch() ` ] [ ] function.
518
518
519
+ ``` mjs
520
+ const res = await fetch (' https://nodejs.org/api/documentation.json' );
521
+ if (res .ok ) {
522
+ const data = await res .json ();
523
+ console .log (data);
524
+ }
525
+ ```
526
+
527
+ The implementation is based upon [ undici] ( https://undici.nodejs.org ) , an HTTP/1.1 client
528
+ written from scratch for Node.js. You can figure out which version of ` undici ` is bundled
529
+ in your Node.js process reading the ` process.versions.undici ` property.
530
+
531
+ ## Custom dispatcher
532
+
533
+ You can use a custom dispatcher to dispatch requests passing it in fetch's options object.
534
+ The dispatcher must be compatible with ` undici ` 's
535
+ [ ` Dispatcher ` class] ( https://undici.nodejs.org/#/docs/api/Dispatcher.md ) .
536
+
537
+ ``` js
538
+ fetch (url, { dispatcher: new MyAgent () });
539
+ ```
540
+
541
+ It is possible to change the global dispatcher in Node.js installing ` undici ` and using
542
+ the ` setGlobalDispatcher() ` method. Calling this method will affect both ` undici ` and
543
+ Node.js.
544
+
545
+ ``` mjs
546
+ import { setGlobalDispatcher } from ' undici' ;
547
+ setGlobalDispatcher (new MyAgent ());
548
+ ```
549
+
550
+ ## Related classes
551
+
552
+ The following globals are available to use with ` fetch ` :
553
+
554
+ * [ ` FormData ` ] ( https://nodejs.org/api/globals.html#class-formdata )
555
+ * [ ` Headers ` ] ( https://nodejs.org/api/globals.html#class-headers )
556
+ * [ ` Request ` ] ( https://nodejs.org/api/globals.html#request )
557
+ * [ ` Response ` ] ( https://nodejs.org/api/globals.html#response ) .
558
+
519
559
## Class: ` File `
520
560
521
561
<!-- YAML
You can’t perform that action at this time.
0 commit comments