Skip to content

Instantly share code, notes, and snippets.

@esironal
Created October 2, 2018 18:13
Show Gist options
  • Save esironal/740bf0e9f43e70663b81e6cd26729a63 to your computer and use it in GitHub Desktop.
Save esironal/740bf0e9f43e70663b81e6cd26729a63 to your computer and use it in GitHub Desktop.
fetch-example.js
var content = document.getElementById('content');
fetch('//api.github.com/users/esironal')
.then(function (res) {
if (res.status >= 400) {
throw new Error("Bad response from server");
}
return res.json();
})
.then(function (user) {
content.innerHTML = JSON.stringify(user, null, ' ');
})
.catch(function (err) {
content.innerHTML = err.message;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment