basic/Vanilla.js
[Vanilla.js] fetch()와 axios
ekgoddldi
2021. 2. 9. 03:21
fetch는 js 내장 함수
axios는 별도로 설치해야함
둘다 비동기 통신 지원
http://teamaqua.github.io/JSONTest/
JSON Test by teamaqua
JSON Test.com JSON Test.com is a testing platform for programs utilizing JavaScript Object Notation (JSON). To use, just make a request to servicename.jsontest.com. For example, calling http://ip.jsontest.com will return your IP address in JSON-formatted f
teamaqua.github.io
async() => {
const res = await fetch('http://date.jsontest.com',{
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
})
const result = await res.json()
}
axios.post('http://date.jsontest.com')
.then(res => alert(res.data.date))
|
axios 라이브러리는 HTTP요청을 Promise 기반으로 처리가 된다
비동기적으로 동작하는 자바스크립트를 동기적으로 처리하는 방법 = 콜백함수, promise함수