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
If the `fetch` operation _returns a response that is not deemed `OK`_ (the
139
+
If the `fetch` operation _causes a response that is not deemed `OK`_ (the
139
140
definition of which
140
141
[can be found here](https://developer.mozilla.org/en-US/docs/Web/API/Response/ok))
141
142
then an exception is raised.
142
143
143
144
Assuming an `OK` response, the following methods are available to you to access
144
145
the data returned from the server:
145
146
146
-
*`response.arrayBuffer()` returns a Python [memoryview](https://docs.python.org/3/library/stdtypes.html#memoryview) of the response. This is equivalent to the [`arrayBuffer()` method](https://developer.mozilla.org/en-US/docs/Web/API/Response/arrayBuffer) in the browser based `fetch` API.
147
-
*`response.blob()` returns a JavaScript [`blob`](https://developer.mozilla.org/en-US/docs/Web/API/Response/blob) version of the response. This is equivalent
147
+
*`await fetch("https://example.com").arrayBuffer()` returns a Python [memoryview](https://docs.python.org/3/library/stdtypes.html#memoryview) of the response. This is equivalent to the [`arrayBuffer()` method](https://developer.mozilla.org/en-US/docs/Web/API/Response/arrayBuffer) in the browser based `fetch` API.
148
+
*`await fetch("https://example.com").blob()` returns a JavaScript [`blob`](https://developer.mozilla.org/en-US/docs/Web/API/Response/blob) version of the response. This is equivalent
148
149
to the [`blob()` method](https://developer.mozilla.org/en-US/docs/Web/API/Response/blob) in the browser based `fetch` API.
149
-
*`response.bytearray()` returns a Python [`bytearray`](https://docs.python.org/3/library/stdtypes.html#bytearray) version of the response.
150
-
*`response.json()` returns a Python datastructure representing a JSON serialised payload in the response.
151
-
*`response.text()` returns a Python string version of the response.
152
-
153
-
!!! warning
154
-
155
-
Unlike the browser based `fetch` API, you **do not need to await** the
156
-
methods listed above, in order to get the data from the response.
150
+
*`await fetch("https://example.com").bytearray()` returns a Python [`bytearray`](https://docs.python.org/3/library/stdtypes.html#bytearray) version of the response.
151
+
*`await fetch("https://example.com").json()` returns a Python datastructure representing a JSON serialised payload in the response.
152
+
*`await fetch("https://example.com").text()` returns a Python string version of the response.
157
153
158
154
The underlying browser `fetch` API has [many request options](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options)
159
155
that you should simply pass in as keyword arguments like this:
@@ -162,7 +158,7 @@ that you should simply pass in as keyword arguments like this:
Should you need access to the underlying [JavaScript response object](https://developer.mozilla.org/en-US/docs/Web/API/Response), you can find it as `response._response()`.
0 commit comments