This file contains hidden or 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
fetch('url') | |
.then((response) => response.json()) | |
.then((data) => console.log(data)) | |
.catch((error) => console.log(error)); |
This file contains hidden or 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
axios({ | |
url: "http://api.com", | |
method: "POST", | |
header: { | |
"Content-Type": "application/json", | |
}, | |
data: { name: "Sabesan", age: 25 }, | |
}); |
This file contains hidden or 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
axios.get(url) | |
.then((response) => console.log(response)) | |
.catch((error) => console.log(error)); |
This file contains hidden or 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
fetch(url, { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify(data), | |
}) | |
.then((response) => response.json()) | |
.catch((error) => console.log(error)); |
This file contains hidden or 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
fetch(url) | |
.then((res) => { | |
// handle response | |
}) | |
.catch((error) => { | |
// handle error | |
}); |
This file contains hidden or 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 controller = new AbortController(); | |
setTimeout(() => controller.abort(), 1000); | |
try { | |
let response = await fetch('/long-operation', { | |
signal: controller.signal | |
}); | |
} catch(err) { | |
if (err.name == 'AbortError') { | |
console.log('Aborted!'); |
This file contains hidden or 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 controller = new AbortController(); | |
let signal = controller.signal; | |
fetch(url, { | |
signal: controller.signal | |
}); | |
signal.addEventListener('abort', | |
() => console.log('abort!') | |
); |
This file contains hidden or 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
fetch('/page', { | |
referrer: '' | |
}); |
This file contains hidden or 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
fetch('http://site.com/file', { | |
integrity: 'sha256-abcdef' | |
}); |
This file contains hidden or 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
window.onunload = function() { | |
fetch('/analytics', { | |
method: 'POST', | |
body: "statistics", | |
keepalive: true | |
}); | |
}; |