fetch(url) // Call the fetch function passing the url of the API as a parameter. Pas d'options: GET .then(function(data) { // Your code for handling the data you get from the API }) .catch(function(e) { console.error(e) });
fetch(url) .then((data) => data.json()) // Transform the data into json .then(function(objet) { // objet JSON }) })
var myHeaders = new Headers(); myHeaders.append("x-access-token", "goldapi-3qem6ukfijcdr6-io"); myHeaders.append("Content-Type", "application/json"); var requestOptions = { method: 'GET', headers: myHeaders, redirect: 'follow' }; fetch("https://www.goldapi.io/api/XAU/USD", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error));