-
Notifications
You must be signed in to change notification settings - Fork 0
/
async-fetch.html
55 lines (41 loc) · 1.49 KB
/
async-fetch.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<!-- Load babel 5 - babel-core
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.38/browser.js"></script> -->
<script>
// Create a function
const githubReuquest = async(loginName) => {
try {
var response = await fetch( `https://api.github.com/users/${loginName}/followers`);
var json = await response.json();
var followerList = json.map(user => user.login);
console.log(followerList);
} catch(e) {
console.log("Data didn't load", e);
}
};
githubReuquest('dandyxu');
// Adjust as an anonymous function
(async(loginName) => {
try {
var response = await fetch( `https://api.github.com/users/${loginName}/followers`);
var json = await response.json();
var followerList = json.map(user => user.login);
console.log(followerList);
} catch(e) {
console.log("Data didn't load", e);
}
})('dandyxu');
</script>
<title>Async and Fetch</title>
</head>
<body>
<h1>Hit the pit</h1>
<h2>Async and Fetch</h2>
<ul>
<li>async()</li>
<li>fetch</li>
</ul>
</body>
</html>