Skip to content

Instantly share code, notes, and snippets.

@serdarcevher
Created June 30, 2020 18:22
Show Gist options
  • Save serdarcevher/36096a082df925aecd1f92451adf54f8 to your computer and use it in GitHub Desktop.
Save serdarcevher/36096a082df925aecd1f92451adf54f8 to your computer and use it in GitHub Desktop.
An async/await example using fetch api
<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