ivapopova

fetchGitHubApi.js

Jan 27th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. let output = document.querySelector('#output');
  2.  
  3. let userName = `WWWCourses`;
  4. let githubAPI = `https://api.github.com/users/${userName}/repos`;
  5.  
  6. async function fetchAsync (url) {
  7. console.log(`Fetching from: ${url}`);
  8.  
  9. // await response of fetch call
  10. let response = await fetch(url);
  11.  
  12. // only proceed once promise is resolved
  13. let data = await response.json();
  14.  
  15. console.log(`@@@@@`);
  16. console.dir(data);
  17.  
  18. // only proceed once second promise is resolved
  19. return data;
  20. }
  21.  
  22. let getReposNames = function(dataArr){
  23. console.dir(dataArr);
  24.  
  25. dataArr.forEach( e => output.innerHTML += `<li>${e.name}</li>`)
  26. }
  27.  
  28.  
  29. // trigger async function
  30. fetchAsync(githubAPI)
  31. .then(dataArr => getReposNames(dataArr))
  32. .catch(reason => console.log(reason.message))
Add Comment
Please, Sign In to add comment