Skip to content

Instantly share code, notes, and snippets.

@fatboab
Created October 4, 2016 22:23
Show Gist options
  • Select an option

  • Save fatboab/7cdeda5bfa2361bafe457df3979260f1 to your computer and use it in GitHub Desktop.

Select an option

Save fatboab/7cdeda5bfa2361bafe457df3979260f1 to your computer and use it in GitHub Desktop.
Understanding fetch and promises
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