HTTP 요청을 보낼 때 fetch와 axios 중 뭘 써야 하나요?
fetch vs axios 비교:
// fetchconst res = await fetch("/api/users");if (!res.ok) throw new Error("Failed");const data = await res.json();// axiosconst { data } = await axios.get("/api/users");// 에러는 자동으로 throw
추천: 간단한 요청은 fetch, 인터셉터/에러 처리가 중요하면 axios
댓글 1
fetch vs axios 비교:
fetchaxios설치브라우저 내장npm install 필요JSON 파싱수동 (.json())자동에러 처리4xx/5xx도 resolve4xx/5xx는 reject인터셉터없음있음취소AbortControllerCancelToken추천: 간단한 요청은 fetch, 인터셉터/에러 처리가 중요하면 axios