Created
June 13, 2018 17:00
-
-
Save Ormadont/8e01fdba6532b6961d6ed6884dbea795 to your computer and use it in GitHub Desktop.
Boilerplate code necessary to create a GET request using the fetch()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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