Re: [whatwg/fetch] Editorial: Reword how-to section to explain how to use callbacks & controller (PR #1614)

@noamr commented on this pull request.



> +  <p>This is the most common way in which clients handle a <a for=/>response</a>, for example
+  <a lt="fetch a classic script">scripts</a> and <a lt="fetch a style resource">style resources</a>.
+  The <a for=/>response</a>'s <a for=response>body</a> is downloaded in its entirety into a
+  <a>byte sequence</a>, and then processed by the <a for=request>client</a>.
+
+  <p>To process a <a for=/>response</a> upon completion, pass an algorithm to the
+  <a for=fetch><i>processResponseConsumeBody</i></a> argument of <a for/>fetch</a>. The given
+  algorithm accepts a <a for=/>response</a> and the final contents.
+  The final contents could be null if there was
+  a <a>network error</a>, failure if there was an error while downloading, or a <a>byte sequence</a>
+  representing the successfully downloaded <a for=response>body</a>.
+
+  <div id=example-callback-upon-completion class=example>
+   <ol>
+    <li><p>Let <var>request</var> be a <a for=/>request</a> whose <a for=request>URL</a> is
+    "https://stuff.example.com", and whose <a for=request>client</a> is <a>this</a>'s

A good question! The spec explains more about it in [the previous section](https://fetch.spec.whatwg.org/#ref-for-concept-request-client%E2%91%A1%E2%91%A4). In the common case you should have a client, and it's usually the relevant settings object of a [platform object](https://webidl.spec.whatwg.org/#dfn-platform-object), or an element's node document's relevant settings object. Where you might not have a client is advanced cases where the fetching is not directly web-exposed, and then you have to set up several other request parameters yourself (origin, policy container...)

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/pull/1614#discussion_r1130394705
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/pull/1614/review/1331954229@github.com>

Received on Thursday, 9 March 2023 04:05:35 UTC