Skip to content

Instantly share code, notes, and snippets.

@robinloeffel
Last active June 23, 2017 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinloeffel/2e36004b042beecd69a631b6af032eb4 to your computer and use it in GitHub Desktop.
Save robinloeffel/2e36004b042beecd69a631b6af032eb4 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>fetch and async await</title>
<style type="text/css">
html {
font-size: 18px;
font-family: sans-serif;
line-height: 1.6;
color: #333;
}
</style>
</head>
<body>
<h1>Suh dud</h1>
<p>My contents will be replaced...</p>
<script>
const getUsers = async (url) => {
const req = await fetch(url),
res = await req.json(),
p = document.querySelector('p'),
rand = Math.round(Math.random() * 9);
p.innerHTML = `I am <b>${res[rand].name}</b> and my mail is <b>${res[rand].email}</b>.`;
};
getUsers('https://jsonplaceholder.typicode.com/users');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment