Last active
February 9, 2021 11:58
-
-
Save sabesansathananthan/51d738ab6fd5df6b1442644f113c3be5 to your computer and use it in GitHub Desktop.
Axios Vs Fetch
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
const controller = new AbortController(); | |
const signal = controller.signal; | |
const options = { | |
method: 'POST', | |
signal: signal, | |
body: JSON.stringify({ | |
firstName: 'Sabesan', | |
lastName: 'Sathananthan' | |
}) | |
}; | |
const promise = fetch('/login', options); | |
const timeoutId = setTimeout(() => controller.abort(), 5000); | |
promise | |
.then(response => {/* handle the response */}) | |
.catch(error => console.error('timeout exceeded')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment