axios / axios

Promise based HTTP client for the browser and node.js

Home Page:https://axios-http.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing custom props via axios config

Alex-Sokolov opened this issue · comments

Describe the bug
We use some custom parameters via axios configuration. They are used in the response interceptor. Sometimes there may be a lot of information there, so the option to pass it through the headers or params is not suitable for us because of the length limit

To Reproduce

  • Open: https://jsfiddle.net/w2rmhy4c/1/
  • Attach axios 0.18 (uncomment line with axios@0.18.0)
  • Run fiddle (console show true)
  • Attach axios 0.19 (uncomment line with axios@0.19.0)
  • Run fiddle (console show undefined)

Expected behavior
Custom config parameter passed. Or the ability to use another config option to pass custom data.

Environment:

  • Axios Version 0.18/0.19

Additional context/Screenshots
First messages with axios 0.18, second with 0.19

I have the same problem

I need this too. I had this working in 0.18 but it stopped working in 0.19

I used something like this:

    await axios({
      url: '/search',
      method: 'GET',
      params,
      myCustomParameter: true
    } as ICustomAxiosRequestConfig)

but it no longer shows up in the interceptor config:

axios.interceptors.request.use(function (config) {
})

Edit: just confirmed this works in 0.18.1 so I'm reverting back for now

Same Here. Reverting back to 18.1 works.

Revert to 18.1 as well

Me too. But why 0.19.0 can't do?

Same here. I'm not able to use custom param in AxiosRequestConfig in 0.19.0 anymore. It would be awesome if there was possibility to use some custom id per request. I'm using response interceptor for global error handling but in a few requests (2-3 of 50) I need different behavior.

I found 0.19 introduce mergeConfig to filter out config.

https://github.com/axios/axios/blob/master/lib/core/mergeConfig.js#L18-L42

so, What should I do, i need config resetful API

Either revert back to v.18 or wait for a fix.

When to Consider Re-support ? 😃

need this too

BLOODY +1

i lost 4h of work until found this issue

This is why I was thinking about something like #1890 ... hope we cen resolve it fast.

I revert back to axios@0.18.0, and there is no BREAKING CHANGE described in 0.19.0 ??!!😱️

commented

+1

Need this too. Revert to 0.18.0 as well.

I think axios should consider opening the interface to custom configuration parameters or backing out the version

This change is already in master, it's a matter of releasing a new version, possibly this upcoming week, cc @emilyemorehouse, this is the PR: https://github.com/axios/axios/pull/2207/files

sorry guys for the inconvenience, hopefully we can have a new version released soon, in the meantime using 0.18 is the best alternative

No need to filter out stuff like this in Javascript. Being able to do stuff like this is one of the amazing parts of the language!

I'm still think that we should create something similar to what I described in #1890 in the future releases. It has some advantages I can think of right now:

  1. it gives us a standard way to deal with custom data in the request objects (this helps us when working with e.g. interceptors, which is a strong point when choosing axios over other http libraries)
  2. we could add to the documentation as many people don't know (or are scared) that request object is untouched (well at least it was until now).
  3. when contributing we would possibly prevent issues like this one from happening again

I'm not saying that the object/property name should be userData as described in the issue, but it surely is worth a discussion.

Any updates on on this? Still stuck with 0.18.1 due to this. I get the love for typescript, but please revert this to the previous behavior :(

Yeah, I just ran into the same issue for my vue app. I just wanted to mock some delay function for the requests, to test the app's stability. An update or workaround for this would be nice.

Great lib, but same for me. I need custom properties

+1

Yeah, custom properties will be very helpful. Thank you, guys for this awesome tool!

Fixed in #2207.

commented

Same, param is missing, 18.1 is a solution (for now). Thanks @Alex-Sokolov.

commented

Same, param is missing, 18.1 is a solution (for now). Thanks @Alex-Sokolov.

But 0.19.1 should solves this. We've updated and tested this successfully, so there is no need for a downgrade anymore.