Last active
December 15, 2017 23:07
-
-
Save halkeand/1f2e915fc6198899cbac2fe78b42c768 to your computer and use it in GitHub Desktop.
fetch-and-process
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
const render = (data) => console.log(data) | |
const apiUrl = 'https://jsonplaceholder.typicode.com/albums' | |
const fetchAsync = async (url) => { | |
let resp = await fetch(url) | |
let data = await resp.json() | |
return data | |
} | |
const fetchAndProcess = (url, process) => { | |
return fetchAsync(url) | |
.then(data => process(data)) | |
.catch(e => process(e.message)) | |
} | |
fetchAndProcess(apiUrl, render) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment