The Fetch API provides an interface for fetching resources (including across the network). It is a more powerful and flexible replacement for XMLHttpRequest
.
Note: This feature is available in Web Workers
The Fetch API provides an interface for fetching resources (including across the network). It is a more powerful and flexible replacement for XMLHttpRequest
.
Note: This feature is available in Web Workers
The Fetch API uses Request
and Response
objects (and other things involved with network requests), as well as related concepts such as CORS and the HTTP Origin header semantics.
For making a request and fetching a resource, use the fetch()
method. It is a global method in both Window
and Worker
contexts. This makes it available in pretty much any context you might want to fetch resources in.
The fetch()
method takes one mandatory argument, the path to the resource you want to fetch. It returns a Promise
that resolves to the Response
to that request — as soon as the server responds with headers — even if the server response is an HTTP error status. You can also optionally pass in an init
options object as the second argument (see Request
).
Once a Response
is retrieved, there are a number of methods available to define what the body content is and how it should be handled.
You can create a request and response directly using the Request()
and Response()
constructors, but it's uncommon to do this directly. Instead, these are more likely to be created as results of other API actions (for example, FetchEvent.respondWith()
from service workers).
Find out more about using the Fetch API features in Using Fetch, and study concepts in Fetch basic concepts.
Specification |
---|
Fetch Standard # fetch-method |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
Fetch_API |
42 | 14 | 39 | No | 29 | 10.1 | 42 | 42 | 39 | 29 | 10.3 | 4.0 |
authorization_removed_cross_origin |
No | No | 111 | No | No | 16.1 | No | No | 111 | No | 16.1 | No |
blob_data_support |
48 | 79 | 39 | No | 35 | 10.1 | 43 | 48 | 39 | 35 | 10.3 | 5.0 |
init_attributionReporting_parameter |
117 | 117 | No | No | 103 | No | 117 | 117 | No | No | No | No |
init_keepalive_parameter |
66 | 15 | No | No | 53 | 13 | 66 | 66 | No | 47 | 13 | 9.0 |
init_priority_parameter |
101 | 101 | No | No | 87 | No | 101 | 101 | No | 70 | No | 19.0 |
init_referrerPolicy_parameter |
52 | 79 | 52 | No | 39 | 11.1 | 52 | 52 | 52 | 41 | No | 6.0 |
init_signal_parameter |
66 | 16 | 57 | No | 53 | 11.1 | 66 | 66 | 57 | 47 | 11.3 | 9.0 |
worker_support |
42 | 14 | 39 | No | 29 | 10.1 | 42 | 42 | 39 | 29 | 10.3 | 4.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API