Last active
January 15, 2018 14:27
-
-
Save ultim8k/477fe88e1cc6b9de44014fe60aef2543 to your computer and use it in GitHub Desktop.
Using js fetch to GET json data
This file contains hidden or 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
// Voila the all new JS fetch | |
fetch('https://bloody-data-json-url', { | |
method: 'GET', | |
// Ask API to respond with json | |
headers: new Headers({ | |
'Content-Type': 'application/json' | |
}), | |
mode: 'cors', | |
cache: 'default' | |
}) | |
// transform response | |
.then(res => res.json()) | |
.catch(error => console.error('Error:', error)) | |
.then(data => console.log('Success:', data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment