DEV Community

Cover image for How to use the github API on your personal site
Jaden Concord
Jaden Concord

Posted on • Edited on

How to use the github API on your personal site

I recently came across the nice Github API that I used to create a list of my repositories on my personal site.

The API is very simple and it doesn't really need to be explained. To get the repositories of a user you would make a request to:

https://api.github.com/users/<USERNAME>/repos
Enter fullscreen mode Exit fullscreen mode

And you will get an array of repositories of the specified user which you can use to create a list of your repositories. Here is a simple example:

  // Needs to be inside an async function
  const response = await fetch('https://api.github.com/users/<USERNAME>/repos');
  const data = await response.json();
  var result = [];
  if (data.length)
  data.forEach(repo => {
    result.push({
      name: repo.name,
      description: repo.description || '',
      url: repo.html_url,
    })
  });
Enter fullscreen mode Exit fullscreen mode

That gives you a simplified array of your repos.

Top comments (0)