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

Added getUri method #1712

Merged
merged 3 commits into from Aug 7, 2018

Conversation

@delirius325
Copy link
Contributor

commented Aug 6, 2018

This is a new feature to get the built URI of an axios instance. It's been added in regards to this issue #1624 , I thought the use-case was interesting and I didn't think it was a good idea to include this feature in a third-party module.

This code

const axios = require('axios');
const fakeConfig = {
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  },
  params: {
    idClient: 1,
    idTest: 2,
    testString: 'thisIsATest'
  }
}
console.log(axios.getUri(fakeConfig));

Outputs

/user/12345?idClient=1&idTest=2&testString=thisIsATest

delirius325 added some commits Aug 6, 2018

@atrauzzi

This comment has been minimized.

Copy link
Contributor

commented Aug 6, 2018

And just to confirm, is this method available on an already configured instance?

const axiosInstance = axios.create({ baseUrl: "..." });

console.log(axiosInstance.getUri({...moreconfig...}));
@delirius325

This comment has been minimized.

Copy link
Contributor Author

commented Aug 6, 2018

@atrauzzi

Yup! Because this line

config = mergeConfig(this.defaults, config);

Takes the default configs and merge them with the specified config. Therefore you could call .getUri()without any new configs and it should return the already configured values.

Cheers 😄,

@atrauzzi

This comment has been minimized.

Copy link
Contributor

commented Aug 6, 2018

It's xmas in August.

Looking at the changeset, man, I guess I was right about it being a pinky-stretch away, eh? 😄

@delirius325

This comment has been minimized.

Copy link
Contributor Author

commented Aug 6, 2018

Yeah, it was crazy simple.. I had the solution Friday before closing my laptop and when I opened it up this morning I was like : "Well, could've committed that Friday 😅 ".

Now just gotta wait for someone to approve the change and merge it to axios 🤞 !

@emilyemorehouse
Copy link
Member

left a comment

@delirius325 can you add documentation to the README for the new method?

@delirius325

This comment has been minimized.

Copy link
Contributor Author

commented Aug 7, 2018

@emilyemorehouse Done 😄

@emilyemorehouse emilyemorehouse merged commit 4f98acc into axios:master Aug 7, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@martin-yin

This comment has been minimized.

Copy link

commented Jun 4, 2019

Wow, look what I found. Can you add geturi to the introduction?
Because when I read the source code, I saw this method, and at first I wanted to know what he was doing.
I didn't see his code example in Markdown. So I hope you can add his code example to Markdown so that you can see at a glance that this is the way I want to use it.

image

@delirius325

This comment has been minimized.

Copy link
Contributor Author

commented Jun 4, 2019

Hi @martin-yin! I welcome you to contribute to the documentation and add the example 😄 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.