@@ -8380,6 +8380,56 @@ correctly. This section aims to give some advice.
8380
8380
8381
8381
<p class=XXX> This is a work in progress.
8382
8382
8383
+ <h3 id=fetch-elsewhere-request>Constructing a request</h3>
8384
+
8385
+ <p> The first step in <a for=/>fetching</a> is to create a <a for=/>request</a> , and populate its
8386
+ multiple associated parameters.
8387
+
8388
+ <p> A <a for=/>request</a> oftenmost has a <a for=request>client</a> , which is the
8389
+ <a>environment settings object</a> that initiatated the request, and the receiver of the different
8390
+ <a for=/>response</a> callbacks. It then expects a <a for=request>URL</a> , and an HTTP
8391
+ <a for=request>method</a> , `<code> GET</code> ` by default. `<code> POST</code> ` and
8392
+ `<code> PUT</code> ` requests also accept a <a for=request>body</a> , which is sent together with the
8393
+ request.
8394
+
8395
+ <p> Requests accept an optional <a for=request>header list</a> parameter, custom HTTP headers to be
8396
+ sent alongside the <a for=/>request</a> . Note that sending custom headers may have implications,
8397
+ such as requiring a <a>CORS-preflight fetch</a> , so handle with care.
8398
+
8399
+ <p> One of the most important things when constructing a <a for=/>request</a> is understanding how
8400
+ it's supposed to handle cross-origin resources. This is expressed in the <a for=/>request</a> 's
8401
+ <a for=request>mode</a> . Some features are supposed to work only in the context of the
8402
+ <a>same origin</a> , in which case the "<code> same-origin</code> " <a for=request>mode</a> is
8403
+ appropriate. For new features that require accessing cross-origin resources, "<code> cors</code> "
8404
+ should be used, alongside a <a for=request>credentials mode</a> , which defines whether the
8405
+ <a for=/>request</a> is anonymous or authenticated (e.g. with cookies and client certificates). The
8406
+ "<code> no-cors</code> " <a for=request>mode</a> is used for backwards compatibility with features
8407
+ that existed before the CORS mechanism was introduced. To use "<code> no-cors</code> " in a new
8408
+ feature, please discuss on the <a href=https://github.com/whatwg/fetch>Fetch Github repository</a> .
8409
+ "<code> navigate</code> " and "<code> websocket</code> " are reserved for specific features.
8410
+
8411
+ <p> A <a for=/>request</a> accepts a few security-related parameters that are often configured, such
8412
+ as <a for=request>integrity metadata</a> , a string hash of the actual data that verifies that the
8413
+ received resource matches an expectation, a <a for=request>cryptographic nonce metadata</a> and
8414
+ <a for=request>parser metadata</a> , which allows more fine-grained security via
8415
+ <cite> Content Security Policy</cite> , and <a for=request>referrer policy</a> , which allows the
8416
+ <a for=/>request</a> to use a different <a for=/>referrer policy</a> from the one provided by the
8417
+ <a for=request>client</a> . [[!CSP]] [[!REFERRER]]
8418
+
8419
+ <p> A <a for=/>request</a> also accepts a few metadata parameters, the important one being
8420
+ <a for=request>destination</a> . <a for=request>destinations</a> affect
8421
+ <cite> Content Security Policy</cite> and have other implications such as the
8422
+ `<code> sec-fetch-dest</code> ` header, so they are much more than informative metadata. If a new
8423
+ feature requires a <a for=request>destination</a> that's not in the list of
8424
+ <a for=request>destinations</a> , please file an issue in the
8425
+ <a href=https://github.com/whatwg/fetch>Fetch Github repository</a> . An aditional metadata
8426
+ paramater is <a for=request>initiator type</a> , which specifies that the <a for=/>fetching</a>
8427
+ should <a for=/>mark resource timing</a> automatically once the <a for=/>response</a> 's
8428
+ <a for=response>body</a> is fully downloaded. [[!CSP]] [[RESOURCE-TIMING]]
8429
+
8430
+ <p> The rest of the parameters for <a for=/>request</a> are used less frequently, and they are
8431
+ documented in detail in the <a href="#requests">Requests</a> section of this standard.
8432
+
8383
8433
8384
8434
<h3 id=fetch-elsewhere-fetch class=no-num>Invoking fetch</h3>
8385
8435
0 commit comments