I need to write coding with Axios. But the example of API documentation is with fetch. When I convert Axios I get a 401 error.
Fetch
API = "https://api.apilayer.com/exchangerates_data";
var myHeaders = new Headers();
myHeaders.append("apikey", API_KEY);
var requestOptions = {
method: "GET",
redirect: "follow",
headers: myHeaders,
};
fetch(`${API}/symbols`, requestOptions)
.then((response) => response.json())
.then((result) => {
setCurrenciesData(result.symbols);
setLoading(false);
})
.catch((error) => setLoading(false));
};
My friend wrote it with Axios like this and it worked. But when I wrote like this, it gave me same error
axios.get(`${API}/symbols&apikey=${API_KEY}`)