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
Here is a brief summary of the formats required to send various http verbs with axios:
GET
: Two ways
First method
axios.get('/user?ID=12345')
.then(function (response) {
// Do something
})
Second method
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
// Do something
})
The two above are equivalent. Observe the params
keyword in the second method.
POST
and PATCH
axios.post('any-url', payload).then(
// payload is the body of the request
// Do something
)
axios.patch('any-url', payload).then(
// payload is the body of the request
// Do something
)
DELETE
axios.delete('url', { data: payload }).then(
// Observe the data keyword this time. Very important
// payload is the request body
// Do something
)
get
requests optionally need a params
key to properly set query parametersdelete
requests with a body need it to be set under a data
key