I want to make a put request with Axios and I got this inside of my action so far:
export function updateSettings(item) {
return dispatch => {
console.log(item)
return axios.put(`/locks`).then(response => {
console.log(response)
})
}
}
When I console.log item
I can see all of things I've typed in my input boxes inside of that object, but later I get 404. I know that I have that URI. Does anyone know how to troubleshoot this problem?
a put response will need an object to send with. the correct axios for put is this:
export function updateSettings(item) {
return dispatch => {
console.log(item)
return axios.put(`/locks`, item).then(response => {
console.log(response)
})
}
}
this is most likely why you get the error because the object to PUT with is undefined.
You can watch this list on the link below, to how to make the correct requests with axios. Axios request methods
A PUT request requires an identifier(e.g id) for the resource and the payload to update with. You seem not to be identifying the resource you want to update, hence 404.
you'd need an id and item like this.
export function updateSettings(id, item) {
return dispatch => {
console.log(item)
return axios.put(`/locks/${id}`, item).then(response => {
console.log(response)
})
}
}