Skip to content

GitHub REST API Starting Guide

Manujaya edited this page Jul 29, 2021 · 5 revisions

What is GitHub REST API?

GitHub API allows allows user 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 actions.

Preparation

Before Starting You must have proper authentications. 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 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 image below. (Tip - Remember to give Expiration Date)

Personal Access Token

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:

Own User Profile

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

Eg:

All Repos

(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:

All Issues assigned to you

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

Eg:

Creating a Repo

References

Clone this wiki locally