-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaulajs21-E.html
More file actions
54 lines (41 loc) · 1.42 KB
/
Copy pathaulajs21-E.html
File metadata and controls
54 lines (41 loc) · 1.42 KB
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
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Aula 21</title>
<script>
//https://flaviocopes.com/fetch-api/
//https://scotch.io/tutorials/how-to-use-the-javascript-fetch-api-to-get-data
var jsonMessagte;
function pageSetup() {
console.log("Page setup...");
}
function showMessage(message){
console.log(message);
document.getElementById("codeBox").innerHTML = JSON.stringify(message);
}
function callApi() {
var gitUserName = document.getElementById("gitUserName").value;
var url = 'https://api.github.com/users/' + gitUserName;
fetch(url) // Call the fetch function passing the url of the API as a parameter
.then(response => response.json())
//.then(data => document.getElementById('codeBox').innerHTML = data)
.then(data => showMessage(data))
.catch(function(error) {
// This is where you run code if the server returns any errors
console.log(error);
});
}
</script>
<style>
</style>
</head>
<body onload="pageSetup();">
<h1>JavaScript Aula 21</h1>
<h2>Arrow Function</h2>
<p><label>GitHub user: </label><input type="text" id="gitUserName" required value="danielscarvalho"></p>
<button onclick="callApi();">Call API</button>
<hr>
<p id="codeBox">
</p>
</body>
</html>