
api 호출하는 과정을 지속적으로 이해하기 위해 과거 api 키 필요 없이 사용했던 conintracker api를 불러온다.
또한, React를 활용하는 것이 아닌 vanilla js 를 통해서 화면을 구성해본다.

async function fetchCoinApi() {
const response = await fetch("https://api.coinpaprika.com/v1/tickers");
const coins = await response.json();
displayCoins(coins);
}
function displayCoins(coins) {
const coinList = document.getElementById('coin-list');
coins.forEach(coin => {
const listItem = document.createElement('li');
listItem.textContent = `${coin.name} (${coin.symbol}): $${coin.quotes.USD.price}`;
coinList.appendChild(listItem);
});
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Coin Prices</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1 {
text-align: center;
}
ul {
list-style-type: none;
padding: 0;
}
li {
background: #f9f9f9;
margin: 10px 0;
padding: 10px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<h1>Current Coin Prices</h1>
<ul id="coin-list"></ul>
<script src="api.js"></script>
<script>
// 페이지 로드 시 fetchCoinApi 함수 호출
fetchCoinApi();
</script>
</body>
</html>