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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3