Home > Net >  How do I perform an axios put request in nodejs with the request body transformed?
How do I perform an axios put request in nodejs with the request body transformed?

Time:03-01

I want the endpoint to have access to an extra field in request object called userData. I could do it with get request like this :

axios.get(`${this.appConfig.getUrlProperties().core}v1.0/address/`,
    { data: req.userData })

But I can't seem to do it with put request in the same manner.

axios.put(`${this.appConfig.getUrlProperties().core}v1.0/address/default/${req.body.address}`,{},
    { data: req.userData })

CodePudding user response:

Looks like you have swapped the config object and payload object. You can try this instead.

axios.put(`${this.appConfig.getUrlProperties().core}v1.0/address/default/${req.body.address}`,
    { data: req.userData }, {})
  • Related