Skip to content

GitHub REST API Starting Guide

Supun Matheesha Suriyaarachchi edited this page Jul 30, 2021 · 5 revisions

What is GitHub REST API?

GitHub API allows users to interact with GitHub by creating and managing repositories, branches, issues, pull requests, and etc. And also by using the Authenticating Tokens user can do some more advanced actions.

Preparation

Before Starting You must have proper authentications. The easiest and basic way is to create a Personal access token. You can do that by following the below steps.

First Navigate to the personal access tokens page and generate a new token (Settings > Developer Settings > Personal access tokens > Generate new Token) Enter the Required Details and You will have a Personal Token as shown in the image below. (Tip - Remember to give Expiration Date)

Now you are Ready to Explore Core REST API concepts.

Basic GitHub API Commands

  1. Getting Your own GitHub User Profile.
curl -i -u your_username:your_token https://api.github.com/user

Eg:

  1. View Repositories of an authenticated user
curl -i -H "Authorization: token <your_token>" https://api.github.com/user/repos

Eg:

(All your Repositories will be Displayed)

you can also list Repositories of another user

curl -i https://api.github.com/users/<user_name>/repos
  1. Get Issues assigned to you
curl -H "Authorization: token <your_token>" https://api.github.com/issues

Eg:

  1. Create a Repository
curl -H "Authorization: token <your_token>" -d '{"name":"Github API Testing"}' https://api.github.com/user/repos

Eg:

References

Some useful Links on REST APIs and APIs