xxxxxxxxxx
const url = 'https://api.example.com/data';
fetch(url, {
method: 'GET',
headers: {
'Accept': 'application/json', // A simple header
},
})
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then((data) => {
console.log('Response data:', data);
})
.catch((error) => {
console.error('Fetch error:', error);
});