DOM Window.fetch() Method
The fetch() method makes a network request and returns a promise for the response. It's the modern way to load data from a server or API.
Description
The fetch() method starts a network request and returns a promise that fulfills with a Response. Read the body with response.json(), text(), blob() or arrayBuffer(), each of which returns another promise. To send data, pass an options object with method: 'POST', headers and a body, such as JSON.stringify(data).
The promise only rejects on network failure. HTTP errors such as 404 or 500 still fulfill, so check response.ok or response.status. Requests to other origins are subject to CORS, and an AbortController can cancel a request or add a timeout.
By default, cookies are sent only with requests to the same origin; set credentials: 'include' to send them to other origins too. Responses can only be read once, so call res.clone() if you need the body twice, for example to log it and parse it.
Syntax
fetch(resource)
fetch(resource, options)Parameters
- resourceThe URL to request, or a
Requestobject. - optionsOptional. Settings such as
method,headers,body,signalandcredentials.
Return Value
A promise that fulfills with a Response object once the response headers arrive.
Example
Browser Support
The following information will show you the current browser support for the Window.fetch() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





