Skip to content

Instantly share code, notes, and snippets.

@ultim8k
Last active January 15, 2018 14:27
Show Gist options
  • Save ultim8k/477fe88e1cc6b9de44014fe60aef2543 to your computer and use it in GitHub Desktop.
Save ultim8k/477fe88e1cc6b9de44014fe60aef2543 to your computer and use it in GitHub Desktop.
Using js fetch to GET json data
// 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