Reputation: 543
I want to get a JSON from an API in React.js. I'm tried with axios, superagent and fetch but it's doesn't worked?
let token = '****';
let url = 'https://'+ token +'@api.navitia.io/v1/coverage/fr-idf/stop_areas/stop_area%3AOIF%3ASA%3A59491/departures?';
let myInit = {
'method': 'GET'
}
fetch(url, myInit).then((response)=>{
return response.json();
}).then((data)=> {
console.log('ok');
}).catch(function(err){
console.log('Erreur: ' + err);
});
Error: "Request cannot be constructed from a URL that includes credentials"
Upvotes: 4
Views: 5886
Reputation: 21
I think the error is letting you know the problem is it doesnt accept credentials in that manner.
You need to create a X-Auth-Token header and add the token to that. then pass the whole thing
Upvotes: 2
Reputation: 390
Try this changes
let myInit = {
'method': 'GET',
credentials: 'include' // or 'same-origin'
}
Upvotes: -2