Get started with github-api CDN

BSD-3-Clause-Clear licensed

The `github-api` is a popular library for making requests to GitHubs API.

Tags:
  • github
  • api

Stable version

Copied!

How to start using github-api CDN


// Include the GitHub library from the CDN
const GitHub = (() => {
  function GitHub() {}

  GitHub.prototype.getUser = function(username) {
    return new Promise((resolve, reject) => {
      const xhr = new XMLHttpRequest();
      xhr.open('GET', `https://api.github.com/users/${username}`);
      xhr.responseType = 'json';
      xhr.onload = () => {
        if (xhr.status === 200) {
          resolve(xhr.response);
        } else {
          reject(new Error('Error getting user'));
        }
      };
      xhr.onerror = () => {
        reject(new Error('Network Error'));
      };
      xhr.send();
    });
  };

  return GitHub;
})();

// Initialize the GitHub instance
const github = new GitHub();

// Get a user's profile using the GitHub API
github.getUser('username')
  .then(user => console.log(user))
  .catch(error => console.error(error));
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions