Promise

async/await

fetch와 함께 사용하게 되었을 경우

async function getData() {
  try {
    const response = await fetch("<https://api.example.com/data>");
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.log(error);
  }
}

getData();

axios와 함께 사용하게 되었을 경우

import axios from "axios";

async function getData() {
  try {
    const response = await axios.get("<https://api.example.com/data>");
    console.log(response.data); // axios는 자동으로 JSON 변환
  } catch (error) {
    console.log(error);
  }
}

getData();

Fetch