Last active
March 2, 2017 00:20
-
-
Save realph/29b62a0e22dc71ab39ba10e9a48e41ff to your computer and use it in GitHub Desktop.
Await Example
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
/* Github Profile Fetcher */ | |
async function fetchProfile(u) { | |
const res = await fetch(`https://api.github.com/users/${u}`); | |
// 1. Check user exists | |
if (!res) { | |
alert('User does not exist!'); | |
return; | |
} | |
// 2. Display user card | |
const user = await res.json(); | |
const card = `${user.login} - ${user.name}\n📨 {$user.email}\n🌐 {$user.blog}`; | |
alert(card); | |
} | |
fetchProfile('realph'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment