Created
October 4, 2016 22:23
-
-
Save fatboab/7cdeda5bfa2361bafe457df3979260f1 to your computer and use it in GitHub Desktop.
Understanding fetch and promises
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
fetch('http://httpbin.org/get?name=name&password=passwd') | |
.then(response => response.json()) | |
.then( | |
data => console.log(`User - ${data.args.name}`), | |
error => console.log(error.message) | |
); | |
fetch('http://httpbin.org/status/401') | |
.then(response => response.json()) | |
.then( | |
data => console.log(`User -> ${data.args.name}`), | |
error => console.log(error.message) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment