-
Notifications
You must be signed in to change notification settings - Fork 0
/
APIcall axios.html
51 lines (51 loc) · 2.19 KB
/
APIcall axios.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Call Axios</title>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
function fetchApiData() {
try {
var row = [];
axios.get('https://api.coinpaprika.com/v1/coins')//no need for conversion into JSON
.then( response => {//'response' is the common prop used with axios
const coins = response.data;//axios always has data property
for (let i = 0; i < 20; i++) {
let coin = coins[i];
row.push(`
<tr>
<td>${coin.rank}</td>
<td>${coin.name}</td>
<td>${coin.symbol}</td>
</tr>
`);
};
var coinTable = document.querySelector('.root');
coinTable.innerHTML = `
<table>
<caption>Top 20 Coins</caption>
<thead>
<th>Rank</th>
<th>Name</th>
<th>Ticker</th>
</thead>
<tbody>
${row.join('')}
</tbody>
</table>
`
});
}
catch (error) {
console.error;
}
}
document.onload = fetchApiData();
</script>
</head>
<body>
<div class='root'></div>
</body>
</html>