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
Merged

Added getUri method #1712

merged 3 commits into from Aug 7, 2018

Conversation

@delirius325
Copy link
Contributor

@delirius325 delirius325 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
@atrauzzi
Copy link
Contributor

@atrauzzi atrauzzi 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...}));

Loading

@delirius325
Copy link
Contributor Author

@delirius325 delirius325 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 😄,

Loading

@atrauzzi
Copy link
Contributor

@atrauzzi atrauzzi 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? 😄

Loading

@delirius325
Copy link
Contributor Author

@delirius325 delirius325 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 🤞 !

Loading

Copy link
Member

@emilyemorehouse emilyemorehouse left a comment

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

Loading

@delirius325
Copy link
Contributor Author

@delirius325 delirius325 commented Aug 7, 2018

@emilyemorehouse Done 😄

Loading

@martin-yin
Copy link

@martin-yin martin-yin 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

Loading

@delirius325
Copy link
Contributor Author

@delirius325 delirius325 commented Jun 4, 2019

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

Loading

@axios axios locked and limited conversation to collaborators May 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants