npm install axios
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
axios.get(url[, config])
axios.get<Type>(url)
.then(response => {
console.log(response.data);
})
.catch((error) => {
console.log(error);
});
axios.post(url[, data[, config]])
axios.post<Type>(url,{name: 'kim'},{
headers: { Content-Type: `application/json` }
}).then(
response => console.log(response.data);
);
//데이터로 보낼 객체를 따로 정의해서 보내도 된다.
const dataObj = {name: 'kim'};
axios.post<Type>(url,dataObj,{
headers: { Content-type: `application/json` }
}).then(
response => console.log(response.data);
);
axios.patch(url[, data[, config]])
axios.patch<Type>(url,{name: 'kim'},{
headers: { Content-type: `application/json` }
}).then(
response => console.log(response.data);
);
axios.delete(url[, config])
axios.delete<Type>(url, {
headers: { Content-Type: `application/json`},
})
.then(response => {
console.log(response.data);
});
axios.delete<string>(url, {
data: { 여기 넣기 },
headers: { Content-type: `application/json` },
})