Skip to content

Instantly share code, notes, and snippets.

@Ormadont
Created June 13, 2018 17:00
Show Gist options
  • Save Ormadont/8e01fdba6532b6961d6ed6884dbea795 to your computer and use it in GitHub Desktop.
Save Ormadont/8e01fdba6532b6961d6ed6884dbea795 to your computer and use it in GitHub Desktop.
Boilerplate code necessary to create a GET request using the fetch()
// boilerplate code necessary to create a GET request using the 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 => {
return jsonResponse;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment