github api play

In this example below you will see how to do a github api play with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by River-Wood, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright River-Wood ©
  • HTML
  • CSS
  • JavaScript
    

/*Downloaded from https://www.codeseek.co/River-Wood/github-api-play-ppvvzZ */
    


/*Downloaded from https://www.codeseek.co/River-Wood/github-api-play-ppvvzZ */
    // console.log(Promise === P);
Promise.config({
  cancellation: true
})
var thenable = function(){
  return Promise.reject('err');
};
function getP() {
  let p0 = new P((resolve, rejects, onCancel) => {
    fetch("https://api.github.com/users", { method: "get" }).then(res => {
      console.log("status", res.status);
      
      var res1 =thenable().catch(err => {
        console.log('err', err);
        onCancel(() => {
          console.log('promise canceled')
        })
        
      }).then(json => {
        if (!json){
          p0.cancel();
        }
        if (res.status === 200) {
          resolve(json);
        } else {
          rejects(json);
        }
      });

      console.log("....");
    });
  });
  
  return p0;
}

getP()
  .then(
    resp => {
      console.log("resp full", resp);
    },
    resp => {
      console.log("resp fail", resp);
    }
  )


Comments