Created
June 30, 2020 18:22
-
-
Save serdarcevher/36096a082df925aecd1f92451adf54f8 to your computer and use it in GitHub Desktop.
An async/await example using fetch api
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
<script> | |
function getData() { | |
return new Promise(function(resolve) { | |
fetch('https://jsonplaceholder.typicode.com/todos/1') | |
.then(response => response.json()) | |
.then(json => { | |
console.log('İkinci mesaj: veriyi aldık'); | |
resolve(json); | |
}); | |
}); | |
} | |
async function printMessages() { | |
console.log('Birinci mesaj'); | |
let data = await getData(); | |
console.log('Üçüncü mesaj'); | |
console.log(data); | |
console.log(data.title); | |
} | |
printMessages(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment