+ 1

How do I solve a 'name not resolved' error in async await api call?

I made this code to fetch data from an api async function coinDetails(){ try { const result= await fetch (`https://crossorigin.me/https://coinmarketcap.com/api/`); const allData= result.json(); console.log(allData);}catch(error){console.log(error)};} coinDetails(); But I got an error saying 'name not resolved' on my console. Any hint on how to fix this?

13th May 2020, 2:39 PM
Agbo Joel
Agbo Joel - avatar
2 Antworten
+ 4
Agbo Joel I got site can't be reached when I tried 'https://crossorigin.me/', should get some kind of message or status. Try 'https://cors-anywhere.herokuapp.com/https://coinmarketcap.com/api/'. You also need to add await in front of result.json() https://code.sololearn.com/W7Z7veFynuKY/#js
13th May 2020, 4:21 PM
ODLNT
ODLNT - avatar
0
That solved it, thanks!
7th Jun 2020, 8:14 AM
Agbo Joel
Agbo Joel - avatar