axios 통신 방법과 코드 정리

안지수·2023년 9월 11일

<post, get 메서드 정하는 법>

  • post: 처음에 값 데이터베이스 저장할 때 (회원가입, 정보입력하기) -> http 바디에 넘겨줌 -> 정보 숨겨줌
  • get: 간단하게 조회 -> header에 정보 넘겨줌

<post 메서드 코드>

        async function fetchData() {
            try {
                const res = await axios.post('http://127.0.0.1:8080/coordinator/profile', 
                {
                    coordinator_id: 1,
                    nickname: nickname,
                    sns_url: sns_url,
                    image_url: image_url,
                    content: content,
                    gender: male === true ? 'MALE' : 'FEMALE',
                    height: height,
                    weight: weight,
                    total_like: 0,
                    request_count: 0
                },
                {
                    headers: { 'Content-Type': 'application/json'},
                }
                );

                console.log(res);
            } catch (error) {
                console.error(error);
            }
        }

async

await

profile
지수의 취준, 개발일기

0개의 댓글