DEV Community

Discussion on: Axios PUT Verb

Collapse
 
murkrage profile image
Mike Ekkel

It was my understanding that the body isn't necessarily required but it is common for the PUT request to have one. Putting that aside, a different fix for your problem would be to nullify the body:

const handleOrderSign = async (orderId) => {
        const token = await getTokenSilently()
        var response = axios.put(
            `${api.order.url}/${orderId}`,
            null,
            {
                headers: {
                    Authorization: `Bearer ${token}`,
                    'content-type': 'application/json',
                    'x-functions-key': api.order.key,
                },
            }
        )
        if (response.statusCode === 200) {
            console.log(response)
        } else {
            console.error(response)
        }
    }
Enter fullscreen mode Exit fullscreen mode

Mostly because axios needs to have that parameter set. Alternatively you could use the request config instead of using the .put() method.