fetch(주소, 옵션)
네트워크를 통해 데이터의 요청(request) 및 응답(Response)을 처리할수 있습니다.
Promise 인스턴스를 반환합니다.
fetch('주소',{
method: 'GET , POST, PUT , PATCH ,DELETE',
headers:{서버로 전송하는 데이터에 대한 정보를 갖고 있다. },
body:{요청에 대한 데이터를담아서 전송을 한다.(문자데이터로 변경해서 전송해야함)}
})
fetch('주소',{
method: 'GET , POST, PUT , PATCH ,DELETE',
headers:{
'Content-Type:'application/json'
},
body:JSON.stringify(
{
name:'hyemin',
age:29,
}
)
})
.then(res => res.json())
.then(json => console.log(json))
const wrap = async () => {
const res = await fetch('주소')
const json = await res.json();
console.log(json)
}
wrap();