Skip to content

Instantly share code, notes, and snippets.

@dupski
Created May 26, 2018 21:35
Show Gist options
  • Save dupski/e7ee48563202a45afe0598caa47fb478 to your computer and use it in GitHub Desktop.
Save dupski/e7ee48563202a45afe0598caa47fb478 to your computer and use it in GitHub Desktop.
Modern Promise Example
import request from 'axios';
function getUserQuote() {
return request({ url: 'https://randomuser.me/api/', responseType: 'json' })
.then((response) => {
console.log('Got User:', response.data);
return request({ url: 'http://quotes.rest/qod.json', responseType: 'json' });
})
.then((response) => {
console.log('Got Quote:', response.data);
})
.catch((err) => {
console.error(err);
throw err;
});
}
getUserQuote();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment