Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Fetch API

BaselineWidely available *

Note: This feature is available inWeb Workers.

The Fetch API provides an interface for fetching resources (including across the network). It is a more powerful and flexible replacement forXMLHttpRequest.

Concepts and usage

The Fetch API usesRequest andResponse 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 thefetch() method. It is a global method in bothWindow andWorker contexts. This makes it available in pretty much any context you might want to fetch resources in.

Thefetch() method takes one mandatory argument, the path to the resource you want to fetch. It returns aPromise that resolves to theResponse 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 aninit options object as the second argument (seeRequest).

Once aResponse 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 theRequest() andResponse() 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 inUsing Fetch.

Interfaces

Window.fetch() andWorkerGlobalScope.fetch()

Thefetch() method used to fetch a resource.

Headers

Represents response/request headers, allowing you to query them and take different actions depending on the results.

Request

Represents a resource request.

Response

Represents the response to a request.

Specifications

Specification
Fetch
# fetch-method

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp