I would like to have a better understanding of passing data in an Axios Delete request. Here, what I have in the backend for the delete request is in order to delete a user you need to give a specific password. So in the frontend, I need to pass the entered password in "axios.delete" method.
And, I always get this 403 forbidden error with my first approach as below ( that is the way of passing the password is the same as the way of passing the updating data with axios.post or axios.patch method):
export function deleteUser(id, password){
const csrfToken = getCookie('csrftoken');
return axios.delete('/users/' + id + '/', {password: password}, {headers: {'X-CSRFToken': csrfToken}})
}
Luckily, I could finally fix that error by the following approach:
export function deleteUser(id, password){
const csrfToken = getCookie('csrftoken');
return axios.delete('/users/' + id + '/', {headers: {'X-CSRFToken': csrfToken}, data: {password: password}})
}
However, I do not clearly understand why axios.delete('/users/' + id + '/', {headers: {'X-CSRFToken': csrfToken}, data: {password: password}}) works fine but axios.delete('/users/' + id + '/', {password: password}, {headers: {'X-CSRFToken': csrfToken}}) not passing the password data correctly (which causes 403 error) while this approach still works properly for axios.post or axios.patch. Can anyone explaining to me more about this problem?