Skip to content

Instantly share code, notes, and snippets.

@jonasjohansson
Created July 13, 2018 19:04
Show Gist options
  • Save jonasjohansson/595eeca650f7d73138c71d9a4ad87066 to your computer and use it in GitHub Desktop.
Save jonasjohansson/595eeca650f7d73138c71d9a4ad87066 to your computer and use it in GitHub Desktop.
const lat = '56.937783';
const lon = '12.384565899999984';
const url = `https://api.met.no/weatherapi/locationforecastlts/1.3/?lat=${lat}&lon=${lon}`;
fetch(url)
.then(response => {
console.log('response', response);
console.log('response.status:', response.status);
console.log('response.statusText:', response.statusText);
console.log('response.ok:', response.ok);
return response.text();
})
.then(responseBody => (new window.DOMParser()).parseFromString(responseBody, "text/xml"))
.then(responseBody => {
let resp = responseBody.getElementsByTagName('temperature')[0].getAttribute("value");
// console.log('responseBody:', responseBody);
console.log('resp:', resp);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment