Frontend/React
[React/Axios] axios delete 요청 시 body에 data 넣는 방법
_성호_
2022. 10. 20. 12:41
728x90
반응형
🚨 오류 발생
AxiosError message: 'Request failed with status code 400'
axios.delete(`${url}/unlike`, {
projectId: id,
})
axios의 delete를 사용하여 서버에 요청을 할 때, 다음과 같이 data를 전달하면 오류가 발생한다.
💡 해결 방법
axios.delete는 request body를 지원하며 다음과 같이 두개의 매개변수를 허용한다.
axios.delete(url[, config])
👍 config.data는 request body를 설정하는데 사용할 수 있다.
axios.delete(`${url}/unlike`, {
data: {
projectId: id,
},
})
2번째 인자에서 data를 data: {} 형태로 한 번 더 감싸주면서 오류를 해결❗