Answer the question
In order to leave comments, you need to log in
What is the correct way to fetch data via fetch() along with a header from a third party API?
Using Postman, I can get data at the address " https://api.weather.yandex.ru/v1/forecast?lang=ru&... " and with the header "X-Yandex-API-Key: <here is my api key>":
I do the same, but with fetch():
fetch('https://api.weather.yandex.ru/v1/forecast?lang=ru'+ '&lat=' + this.props.city.lat + '&lon=' + this.props.city.lon, {
headers: (new Headers({
'X-Yandex-API-Key': API_KEY
}));
})
.then(resp => resp.json())
.then(res => {
console.log(res)
});
Answer the question
In order to leave comments, you need to log in
Maybe you should try to specify the method: " method: 'GET' "?
fetch('https://api.weather.yandex.ru/v1/forecast?lang=ru'+ '&lat=' + this.props.city.lat + '&lon=' + this.props.city.lon, {
method: 'GET',
headers: (new Headers({
'X-Yandex-API-Key': API_KEY
}))
}).then(resp => resp.json()).then(res => {
console.log(res)
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question