Created
March 31, 2024 02:16
-
-
Save kgust/2df53f0f5084a34d7c3d65939c4d0390 to your computer and use it in GitHub Desktop.
Use JavaScript's native fetch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let promise = fetch(url, { | |
method: "GET", // POST, PUT, DELETE, etc. | |
headers: { | |
// the content type header value is usually auto-set | |
// depending on the request body | |
"Content-Type": "text/plain;charset=UTF-8" | |
}, | |
body: undefined, // string, FormData, Blob, BufferSource, or URLSearchParams | |
referrer: "about:client", // or "" to send no Referer header, | |
// or an url from the current origin | |
referrerPolicy: "strict-origin-when-cross-origin", // no-referrer-when-downgrade, no-referrer, origin, same-origin... | |
mode: "cors", // same-origin, no-cors | |
credentials: "same-origin", // omit, include | |
cache: "default", // no-store, reload, no-cache, force-cache, or only-if-cached | |
redirect: "follow", // manual, error | |
integrity: "", // a hash, like "sha256-abcdef1234567890" | |
keepalive: false, // true | |
signal: undefined, // AbortController to abort request | |
window: window // null | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment