window.fetch
fetch — Fetches a resource from the web.
Description
fetch(mixed resource, [object settings])
Parameters
Name | Description | Type | Default | Optional |
---|---|---|---|---|
resource | url or object. | mixed | No | |
settings | object | Yes |
Settings parameters
- method
Request method, e.g., GET, POST, HEAD, …
- headers
Custom headers for the request.
- body
The body for the request.
- mode
Request mode, e.g., cors, no-cors, same-origin, …
- credentials
Custom credentials for the request.
- cache
Request cache, e.g., no-store, reload, no-cache, …
- redirect
Request redirect: follow, error, manual.
- referrer
Request referrer: no-referrer, client or URL
- referrerPolicy
Request referrer policy, e.g., no-referrer, origin, unsafe-url, …
- integrity
A cryptographic hash that the request must match.
- keepalive
Allow the request to stay alive.
- signal
A signal to communicate with the fetch process.
Return values
Examples
Example #1 – fetch example
Example #2 – fetch error example