I am making a lot of breaks in the process of trying to learn to code and I am generally not satisfied with how it is going for me. But this time I finally managed to get some data from APIs out there and thought it will be better this time. However, as soon as the API is more complex I am stuck.
Could anyone tell me what should I do with this code to get the data? I always get ‘TypeError: Failed to fetch’ in the console.
This is my code:
const url = "http://api.football-data.org/v2/matches";
fetch(url, {
method: "GET",
withCredentials: true,
headers: {
"X-Auth-Token": "ef72570ff371408f9668e414353b7b2e",
"Content-Type": "application/json"
}
})
.then(resp => resp.json())
.then(function(data) {
console.log(data);
})
.catch(function(error) {
console.log(error);
});