Skip to content

Instantly share code, notes, and snippets.

@realph
Last active March 2, 2017 00:20
Show Gist options
  • Save realph/29b62a0e22dc71ab39ba10e9a48e41ff to your computer and use it in GitHub Desktop.
Save realph/29b62a0e22dc71ab39ba10e9a48e41ff to your computer and use it in GitHub Desktop.
Await Example
/* 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