Last active
September 30, 2016 20:33
-
-
Save philippgerbig/7d1bdeb7f106e8a74c3a076db5de7e89 to your computer and use it in GitHub Desktop.
Generator function example with co and ajax request
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
import fetch from 'node-fetch'; | |
// for use in browser you need to import fetch from fetch-polyfill | |
import co from 'co'; | |
co(function *() { | |
const url = 'http://jsonplaceholder.typicode.com/posts/i'; | |
const response = yield fetch(url); | |
const post = yield response.json(); | |
const { title } = post; | |
console.log('Title:', title); | |
}).catch(err => console.error(err.stack)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment