Skip to content

Instantly share code, notes, and snippets.

@brettvaida
Last active November 26, 2017 00:09
Show Gist options
  • Select an option

  • Save brettvaida/a11a8ed085288c8e2664c6a6a4c97b71 to your computer and use it in GitHub Desktop.

Select an option

Save brettvaida/a11a8ed085288c8e2664c6a6a4c97b71 to your computer and use it in GitHub Desktop.
AJAX GET request boilerplate using fetch(). May require polyfill from https://github.com/github/fetch
fetch('https://api-to-call.com/endpoint').then(response => {
if (response.ok) {
return response.json();
} throw new Error('Request failed!');
}, networkError => console.log(networkError.message)
).then(jsonResponse => jsonResponse);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment