Skip to content
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

Support delete body #897

Closed
Christilut opened this issue May 13, 2017 · 7 comments
Closed

Support delete body #897

Christilut opened this issue May 13, 2017 · 7 comments

Comments

@Christilut
Copy link

This is probably a design choice by the axios team and for good reason but I write all my POST/GET/PUTs like this:

const res = await axios.post(url, { 
  data: {
    ...
  }
})

And my server sometimes expects data inside the DELETE request body (which may not be technically according to spec but nonetheless it is common) in which case I have to write my DELETE in this form:

      const res = await axios({
        method: 'DELETE',
        url: 'url',
        data: {
          ...
        }
      })

Which works fine but I'm forced to use the second syntax because the axios.delete doesn't support a request body.

So I would like to request that axios.delete will support a request body.

Thanks

@emkman
Copy link

emkman commented Jun 6, 2017

We often use data with GET requests on the server and they are translated to query params. The lack of data support on certain methods is a big downside for axios in my hopes of more isomorphic code.

@huangche007
Copy link

Thanks, Here I found this answer

@nickuraltsev
Copy link
Member

axiox.delete does support a request body. It accepts two parameters: url and optional config. You can use config.data to set the response body as follows:

axios.delete(url, { data: { foo: "bar" } });

post, put, and patch accept 3 parameters: url, data, and config so you can you can use the second parameter to set the response body like this:

axios.put(url, { foo: "bar" });

Hope it helps!

@charlesrochati
Copy link

I think the README is making it dificult to understand:

  // `data` is the data to be sent as the request body
  // Only applicable for request methods 'PUT', 'POST', and 'PATCH'
  // When no `transformRequest` is set, must be of one of the following types:
  // - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
  // - Browser only: FormData, File, Blob
  // - Node only: Stream, Buffer
  data: {
    firstName: 'Fred'
  },

This part: // Only applicable for request methods 'PUT', 'POST', and 'PATCH' especially.

@namila007
Copy link

please add this comment to the docs

@sprlwrksAprilmintacpineda

@gomezmark
Copy link

what is the difference between these two?

this.$axios.$delete(queryData.url,
        {
          params: { id: String(queryData.id) }
        })
this.$axios.$delete(queryData.url,
        {
          body: { id: String(queryData.id) }
        })

[params] worked on my side

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants