Axios Delete request with body and headers?

后端 未结 11 2145
梦谈多话
梦谈多话 2020-11-28 08:16

I\'m using Axios while programing in ReactJS and I pretend to send a DELETE request to my server.

To do so I need the headers:

headers: {
  \'Authori         


        
11条回答
  •  生来不讨喜
    2020-11-28 08:55

    Actually, axios.delete supports a request body.
    It accepts two parameters: a URL and an optional config. That is...

    axios.delete(url: string, config?: AxiosRequestConfig | undefined)
    

    You can do the following to set the response body for the delete request:

    let config = { 
        headers: {
            Authorization: authToken
        },
        data: { //! Take note of the `data` keyword. This is the request body.
            key: value,
            ... //! more `key: value` pairs as desired.
        } 
    }
    
    axios.delete(url, config)
    

    I hope this helps someone!

提交回复
热议问题