Created
October 15, 2017 09:53
-
-
Save coryhouse/68db344b82b51b99b1063ba9e5071d0e to your computer and use it in GitHub Desktop.
Async/Await example
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
getPosts().then(posts => { | |
console.log(posts.length); | |
}); | |
async function getPosts() { | |
try { | |
const response = await fetch("https://jsonplaceholder.typicode.com/posts"); | |
return response.json(); | |
} catch(error) { | |
console.log(error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return await response.json();