How do I send a DELETE request with axios containing data?
My backend is not picking up the data, and so I'm not sure if this is because It is not possible to send data with axios delete, or if I structured the request wrong.
My Data:
const deleteTrack = (e) =>{ e.preventDefault()
{
dispatch(
deleteTracks({
'user_id':userInfo.id,
'trackitem_id':trackitem._id,
}
))
window.location.reload();
}
}
My request:
export const deleteTracks = (track) => async(dispatch,getState) => {
console.log(track)
try{
dispatch({
type:TRACK_DELETE_REQUEST,
})
const {
userLogin: {userInfo},
} = getState()
const config = {
headers:{
'Content-type':'application/json',
Authorization:`Bearer ${userInfo.token}`
}
}
//Maybe your not supposed to send data
const { data } = await axios.delete(`/api/deletetrackitem/`,config,track)
dispatch({
type:TRACK_DELETE_SUCCESS,
payload:data,
})
}
catch(error){
dispatch({type:TRACK_DELETE_FAIL,
payload:error.response && error.response.data.detail ? error.response.data.detail : error.message,
})
}
}
Thanks