axios | 브라우저, Node.js를 위한 Promise API를 활용하는 HTTP 비동기 통신 라이브러리, 백엔드와 프론트엔드를 연결 |
---|---|
GET | axios.get(url[, config]) |
POST | axios.post(url, data[, config]) |
PUT | axios.put(url, data[, config]) |
DELETE | axios.delete(url[, config]) |
GET
데이터를 요청 (데이터를 가져온다고 생각하면 간편)
export const getFriendList = () => getAxios('/friend/list');
export const acceptFriend = (targetUserId) =>
getAxios(`/friend/request/accept/${targetUserId}`);
POST
데이터를 전송 (보통 데이터를 Message Body에 포함시켜 전송)
export const sendFriendRequest = (targetUserId) =>
postAxios(`/friend/request/${targetUserId}`);
PUT
데이터를 수정 (POST와 비슷)
axios.put("url", {
username: "",
password: ""
})
.then(function (response) {
// response
}).catch(function (error) {
// 오류발생시 실행
})
DELETE
데이터베이스에 저장되어 있는 내용을 삭제
export const deleteFriend = (targetUserId) => {
deleteAxios(`/friend/delete/${targetUserId}`);
};