I struggle with correct syntax on fetching an API while adding to the request the document.URL
.
My request looks like this:
function fetchApi() {
return fetch('https://api.sistrix.com/domain.sichtbarkeitsindex?api_key=myKey&domain=example.com&format=json')
.then(response => {
if (!response.ok) {
return response.text().then(text => {throw new Error(text)});
}
return response.text();
})
}
return fetchApi()
.then(intent => seoSpider.data(intent))
.catch(error => seoSpider.error(error));
It works, like expected. Now I want to replace ‘example.com’ with ‘document.URL’ – but have no success with correct syntax.
I tried it with return fetch('https://api.sistrix.com/domain.sichtbarkeitsindex?api_key=myKey&format=json&domain' + document.URL)
– but it doesn’t work, API doesn’t recognize document.URL
as valid address.