PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 13, 2022

[FIXED] How to access baseURL of axios instance

 October 13, 2022     axios, instance, javascript, reactjs     No comments   

Issue

I put this question up in order for easy access of the solution for fellow developers searching for an answer

//If you have an axios instance declared in a module similar to this, say, api.js

var axios = require('axios');

var axiosInstance = axios.create({
    baseURL: 'https://example.com/foo/bar',
    /* other custom settings */
});

module.exports = axiosInstance;

//If you are accessing the module somewhere else, like this

var api = require('./api');

api.get('relative/path')      //For a typical get call using an instance

But, you want to find the baseURL for some business requirement from an axios instance and not necessarily make a call, how do you find it?


Solution

https://github.com/axios/axios#global-axios-defaults

in your case should be : baseURL = api.defaults.baseURL



Answered By - mrJQuery
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing