0

Trying to make a http request with axios, then accessing some property from request. Property is undefined, although it is present

public getApiURL() {
    axios.get('https://xxxxxxxxx.com/metadata.json')
        .then(res => {
            console.log(res.data); // {"apiUrl":"https://xxxx.com/Api"}
            console.log(res.data.apiUrl); // undefined
        }).catch(err => {
            console.log('error', err);
        })
}
sandum
  • 751
  • 5
  • 13
  • 25

1 Answers1

-1

Try This one

`

public getApiURL=async ()=> {
    try{
       let result= await axios.get('https://xxxxxxxxx.com/metadata.json')
       const data = JSON.parse(result.data);
       console.log(data.apiUrl);
       }catch(err){
           console.log(err);
       }    
}

`

Sanaullah
  • 374
  • 6
  • 11