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 _causes a response that is not deemed `OK`_ (the
140
+
definition of which
141
+
[can be found here](https://developer.mozilla.org/en-US/docs/Web/API/Response/ok))
142
+
then an exception is raised.
143
+
144
+
Assuming an `OK` response, the following methods are available to you to access
145
+
the data returned from the server:
146
+
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
149
+
to the [`blob()` method](https://developer.mozilla.org/en-US/docs/Web/API/Response/blob) in the browser based `fetch` API.
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.
153
+
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)
155
+
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()`.
165
+
166
+
!!! Danger
167
+
168
+
You may encounter [CORS](https://developer.mozilla.org/en-US/docs/Glossary/CORS) errors (especially with reference to a missing
0 commit comments