Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Axios delete request is not taking the body data

I am new to the react redux. Here I have a delete request

export const deleterequest = (url, jdId) =>
    axios.delete(
        url,
        jdId,
        {
            headers: {
                "Authorization": localStorage.getItem("access_token") !== null ? `Bearer ` + localStorage.getItem("access_token") : null,
                "Content-Type": "application/json"
            }
        }
    ).then(data => {
        if (data.status === HttpStatus.OK) {
            return {
                status: data.status,
                payload: data.data
            };
        }
    }).catch(err => {
        return {
            status: err.response ? err.response.data : 'Network error',
            payload: null
        };

So, I tried with this apporch. jdId is an array of strings. So, But when I am using in this way then my request header does not show this data.

So, what is that I am doing wrong. Can any one help me with this ?

like image 395
ganesh Avatar asked Nov 28 '22 05:11

ganesh


1 Answers

delete requests with a body need it to be set under a data key

export const deleterequest = (url, jdId) =>
    axios.delete(
        url,
        { data: jdId },
        {
            headers: {
                "Authorization": localStorage.getItem("access_token") !== null ? `Bearer ` + localStorage.getItem("access_token") : null,
                "Content-Type": "application/json"
            }
        }
    ).then(data => {
        if (data.status === HttpStatus.OK) {
            return {
                status: data.status,
                payload: data.data
            };
        }
    }).catch(err => {
        return {
            status: err.response ? err.response.data : 'Network error',
            payload: null
 };
like image 170
Prabhu Avatar answered Dec 05 '22 03:12

Prabhu