New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
axios.delete - must specify 'data' object? #736
Comments
Nope, this won't work. What you have to pass to Axios is a Request Config Object and in this object you can find the This way: In a
|
@charlesrochati I'm confused. |
If you want to make a You don't use You will send data as the request body ONLY WHEN you are using 'PUT', 'POST', and 'PATCH'. I'm afraid you're using By using Take a look at the links below, you will have a better understanding: https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html [Section 9.7] |
The HTTP DELETE method should not have a request body. DELETE is telling the origin server to remove the resource identified by the URI. |
In my case, I do give a payload as well. But either way, if it works using EDIT: The specification does not disallow/forbid passing a payload. |
There is no shorthand for axios.delete: axios.request(config) axios.get(url[, config]) axios.delete(url[, config]) axios.head(url[, config]) axios.post(url[, data[, config]]) axios.put(url[, data[, config]]) axios.patch(url[, data[, config]]) |
@AkiraLaine the specification also doesn't forbid sending request bodies for GET either. Should axios also allow you to use the short-hand notation for sending request bodies in GET requests as well? |
I'm closing the issue as it's the expected behaviour. |
@rubennorte I think we should support |
@cggaurav it is supported. axios.delete('/some/uri', { body: 'my delete body' }) |
On a side note, On the server the id is showing up in req.query instead of req.params when using axios.delete('/some/uri', {params: { id: 1 } }) like this. Just wanted to throw that out there. |
@aricsangchat that's likely because you're using express which is not affiliated with axios at all. When express refers to // Express
router.get('/:foo/:bar', (req, res) => {
res.json({
query: req.query,
params: req.params
})
}) // Axios
axios.get('/some/uri', { params: { id: 1 } })
.then((response) => console.log(response.data)) The output you'd get from running that would be: {
"query": { "id": 1 },
"params": {
"foo": "some",
"bar": "uri"
}
} |
@jcready Yup thats our setup. |
Where is written that delete cannot have a body (like post)? It would be nice if axios supports this https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-19#page-23 Thank you |
FYI. Fair points that DELETE should not have a body. However, sometimes you're stuck having to send a body when the api is out of your control. e.g. |
const extension_url = 'mycompany.auth0.com'
const access_token = 'abc123'
const user_id = 12345
const role_id = 67890
axios.delete(`https://${extension_url}/users/${role_id}/roles`, {
headers: {
'Authorization': `Bearer ${access_token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify([
user_id
])
}) |
@jcready - For sure and thanks for the example. Just wanted to add some reasoning for why a body may need to be passed on DELETE when using axios. |
@duhseekoh Maybe this will help: #897 (comment) |
I have it working with |
@quinnliu I think choosing to use
axios.delete(URL, {
params: { foo: 'bar' }
}) it's same as sending request to |
Abstraction from axios in api. Params in data: name only
|
When using the alias
axios.delete
, the payload doesn't get sent with the API call if you don't specifydata
.You have to do:
instead of
According to this, you shouldn't have to define
data
. I've been able to use other methods with payload without specifyingdata
.The text was updated successfully, but these errors were encountered: