GitHub API.
GitHub API is Hypermedia based. This is an elementary post introducing how to interact with GitHub API using curl
and the jq
tools.
The GitHub API is based on hypermedia API. The very first request most basic GitHub API:
curl -s https://api.github.com
This is API references within the API, which is a nice part of Hypermedia based APIs.
A Hypermedia Type is a media type that contains native hyperlinking elements that can be used to control application flow. Hypermedia types are SVG, HTML, Atom and so on.
To extract current user URL:
curl https://api.github.com | jq '.current_user_url'
This will give you the output of "https://api.github.com/user"
.
To list my information.
curl -s https://api.github.com/users/ojitha
Get my avatar url:
curl -s https://api.github.com/users/ojitha | jq '.avatar_url'
I can list all of my projects as follows.
curl -s https://api.github.com/users/ojitha/repos | jq .[].name
To get the information about https://ojitha.github.io:
curl -s https://api.github.com/users/ojitha/repos | jq '.[] | select(.name == "ojitha.github.io")'
For some API request you have to provide personal token for authentication:
curl -u ojitha:<token> https://api.github.com/rate_limit