Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix globals, part 11: fetch() #33643

Merged
merged 14 commits into from
Jul 16, 2024
11 changes: 5 additions & 6 deletions files/en-us/_redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8383,8 +8383,8 @@
/en-US/docs/Web/API/GlobalEventHandlers/ontransitioncancel /en-US/docs/Web/API/Element/transitioncancel_event
/en-US/docs/Web/API/GlobalEventHandlers/ontransitionend /en-US/docs/Web/API/Element/transitionend_event
/en-US/docs/Web/API/GlobalEventHandlers/onwheel /en-US/docs/Web/API/Element/wheel_event
/en-US/docs/Web/API/GlobalFetch/GlobalFetch.fetch() /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/GlobalFetch/fetch /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/GlobalFetch/GlobalFetch.fetch() /en-US/docs/Web/API/Window/fetch
/en-US/docs/Web/API/GlobalFetch/fetch /en-US/docs/Web/API/Window/fetch
/en-US/docs/Web/API/Guide/Events/Creating_and_triggering_events /en-US/docs/Web/Events/Creating_and_triggering_events
/en-US/docs/Web/API/HID/onconnect /en-US/docs/Web/API/HID/connect_event
/en-US/docs/Web/API/HID/ondisconnect /en-US/docs/Web/API/HID/disconnect_event
Expand Down Expand Up @@ -9728,7 +9728,7 @@
/en-US/docs/Web/API/ServiceWorkerGlobalScope/activate /en-US/docs/Web/API/ServiceWorkerGlobalScope/activate_event
/en-US/docs/Web/API/ServiceWorkerGlobalScope/caches /en-US/docs/Web/API/WorkerGlobalScope/caches
/en-US/docs/Web/API/ServiceWorkerGlobalScope/claim /en-US/docs/Web/API/Clients/claim
/en-US/docs/Web/API/ServiceWorkerGlobalScope/fetch /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/ServiceWorkerGlobalScope/fetch /en-US/docs/Web/API/WorkerGlobalScope/fetch
/en-US/docs/Web/API/ServiceWorkerGlobalScope/install /en-US/docs/Web/API/ServiceWorkerGlobalScope/install_event
/en-US/docs/Web/API/ServiceWorkerGlobalScope/onmessage /en-US/docs/Web/API/ServiceWorkerGlobalScope/message_event
/en-US/docs/Web/API/ServiceWorkerGlobalScope/periodicsync /en-US/docs/Web/API/ServiceWorkerGlobalScope/periodicsync_event
Expand Down Expand Up @@ -10152,7 +10152,6 @@
/en-US/docs/Web/API/Window/content /en-US/docs/Web/API/Window
/en-US/docs/Web/API/Window/convertPointFromNodeToPage /en-US/docs/Web/API/Window/webkitConvertPointFromNodeToPage
/en-US/docs/Web/API/Window/convertPointFromPageToNode /en-US/docs/Web/API/Window/webkitConvertPointFromPageToNode
/en-US/docs/Web/API/Window/fetch /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/Window/minimize /en-US/docs/Web/API/Window
/en-US/docs/Web/API/Window/mozAnimationStartTime /en-US/docs/Web/API/Animation/startTime
/en-US/docs/Web/API/Window/mozPaintCount /en-US/docs/Web/API/Window
Expand Down Expand Up @@ -10257,7 +10256,7 @@
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout /en-US/docs/Web/API/clearTimeout
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap /en-US/docs/Web/API/createImageBitmap
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/crossOriginIsolated /en-US/docs/Web/API/Window/crossOriginIsolated
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch /en-US/docs/Web/API/Window/fetch
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/indexedDB /en-US/docs/Web/API/Window/indexedDB
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/isSecureContext /en-US/docs/Web/API/Window/isSecureContext
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/origin /en-US/docs/Web/API/Window/origin
Expand Down Expand Up @@ -10308,7 +10307,6 @@
/en-US/docs/Web/API/WorkerGlobalScope/clearTimeout /en-US/docs/Web/API/clearTimeout
/en-US/docs/Web/API/WorkerGlobalScope/close /en-US/docs/Web/API/DedicatedWorkerGlobalScope/close
/en-US/docs/Web/API/WorkerGlobalScope/console /en-US/docs/Web/API/console
/en-US/docs/Web/API/WorkerGlobalScope/fetch /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/WorkerGlobalScope/onclose /en-US/docs/Web/API/DedicatedWorkerGlobalScope/close
/en-US/docs/Web/API/WorkerGlobalScope/onerror /en-US/docs/Web/API/WorkerGlobalScope/error_event
/en-US/docs/Web/API/WorkerGlobalScope/onlanguagechange /en-US/docs/Web/API/WorkerGlobalScope/languagechange_event
Expand Down Expand Up @@ -10648,6 +10646,7 @@
/en-US/docs/Web/API/event.type /en-US/docs/Web/API/Event/type
/en-US/docs/Web/API/event.view /en-US/docs/Web/API/UIEvent/view
/en-US/docs/Web/API/event.which /en-US/docs/Web/API/UIEvent/which
/en-US/docs/Web/API/fetch /en-US/docs/Web/API/Window/fetch
/en-US/docs/Web/API/form.acceptCharset /en-US/docs/Web/API/HTMLFormElement/acceptCharset
/en-US/docs/Web/API/form.action /en-US/docs/Web/API/HTMLFormElement/action
/en-US/docs/Web/API/form.elements /en-US/docs/Web/API/HTMLFormElement/elements
Expand Down
86 changes: 43 additions & 43 deletions files/en-us/_wikihistory.json
Original file line number Diff line number Diff line change
Expand Up @@ -66867,6 +66867,49 @@
"modified": "2020-10-15T22:11:52.818Z",
"contributors": ["wbamberg", "JeffersonScher", "chrisdavidmills"]
},
"Web/API/Window/fetch": {
"modified": "2020-10-15T21:33:25.494Z",
"contributors": [
"mfuji09",
"Wind1808",
"Sheppy",
"Zearin_Galaurum",
"chrisdavidmills",
"TestPolygon",
"bigjilm",
"tkrotoff",
"old_morfey13",
"skellix",
"FranklinYu",
"sideshowbarker",
"tjcrowder",
"DamienCassou",
"fscholz",
"mfulton26",
"SiliconSoldier",
"satyabhimisetty",
"jakubboucek",
"AngeloKai",
"Yaffle",
"cpplearner",
"Konrud",
"BuonOmo",
"kenrick95",
"kmiyashiro",
"xfq",
"arronei",
"valtlai",
"erikadoyle",
"jpmedley",
"runn1ng",
"ysmood",
"jsx",
"Sebastianz",
"George8211",
"matiishyn",
"kscarfone"
]
},
"Web/API/Window/find": {
"modified": "2020-10-16T15:18:21.626Z",
"contributors": [
Expand Down Expand Up @@ -71556,49 +71599,6 @@
"adria"
]
},
"Web/API/fetch": {
"modified": "2020-10-15T21:33:25.494Z",
"contributors": [
"mfuji09",
"Wind1808",
"Sheppy",
"Zearin_Galaurum",
"chrisdavidmills",
"TestPolygon",
"bigjilm",
"tkrotoff",
"old_morfey13",
"skellix",
"FranklinYu",
"sideshowbarker",
"tjcrowder",
"DamienCassou",
"fscholz",
"mfulton26",
"SiliconSoldier",
"satyabhimisetty",
"jakubboucek",
"AngeloKai",
"Yaffle",
"cpplearner",
"Konrud",
"BuonOmo",
"kenrick95",
"kmiyashiro",
"xfq",
"arronei",
"valtlai",
"erikadoyle",
"jpmedley",
"runn1ng",
"ysmood",
"jsx",
"Sebastianz",
"George8211",
"matiishyn",
"kscarfone"
]
},
"Web/API/queueMicrotask": {
"modified": "2020-10-15T22:21:06.789Z",
"contributors": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: fetch() global function
title: "Window: fetch() method"
short-title: fetch()
slug: Web/API/fetch
page-type: web-api-global-function
slug: Web/API/Window/fetch
page-type: web-api-instance-method
browser-compat: api.fetch
---

{{APIRef("Fetch API")}}{{AvailableInWorkers}}
{{APIRef("Fetch API")}}

The global **`fetch()`** method starts the process of fetching a resource from the network, returning a promise that is fulfilled once the response is available.
The **`fetch()`** method of the {{domxref("Window")}} interface starts the process of fetching a resource from the network, returning a promise that is fulfilled once the response is available.

The promise resolves to the {{domxref("Response")}} object representing the response to your request.

Expand Down Expand Up @@ -197,7 +197,8 @@ const myImage = document.querySelector("img");

const myRequest = new Request("flowers.jpg");

fetch(myRequest)
window
.fetch(myRequest)
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
Expand All @@ -211,7 +212,7 @@ fetch(myRequest)
```

In our [Fetch Request with init example](https://github.com/mdn/dom-examples/tree/main/fetch/fetch-request-with-init) (see [Fetch Request init live](https://mdn.github.io/dom-examples/fetch/fetch-request-with-init)) we do the same thing except that we pass in an _options_ object when we invoke `fetch()`.
In this case, we can set a {{httpheader("Cache-Control")}} value to indicate what kind of cached responses we're okay with:
In this case, we can set a {{HTTPHeader("Cache-Control")}} value to indicate what kind of cached responses we're okay with:

```js
const myImage = document.querySelector("img");
Expand Down Expand Up @@ -260,6 +261,7 @@ const req = new Request("flowers.jpg", options);

## See also

- {{domxref("WorkerGlobalScope.fetch()")}}
- [Fetch API](/en-US/docs/Web/API/Fetch_API)
- [ServiceWorker API](/en-US/docs/Web/API/Service_Worker_API)
- [HTTP access control (CORS)](/en-US/docs/Web/HTTP/CORS)
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/window/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ _This interface inherits methods from the {{domxref("EventTarget")}} interface._
- : Accepts a variety of different image sources, and returns a {{jsxref("Promise")}} which resolves to an {{domxref("ImageBitmap")}}. Optionally the source is cropped to the rectangle of pixels originating at _(sx, sy)_ with width sw, and height sh.
- {{domxref("Window.dump()")}} {{Non-standard_Inline}}
- : Writes a message to the console.
- {{domxref("fetch", "Window.fetch()")}}
- {{domxref("Window.fetch()")}}
- : Starts the process of fetching a resource from the network.
- {{domxref("Window.find()")}} {{Non-standard_Inline}}
- : Searches for a given string in a window.
Expand Down
Loading