Git & GitHub

Get Download Count of GitHub Repo’s Releases Using The REST API

GitHub Repository Release Count

Before going on to the main part let’s have a small talk about API. The full form of API is “Application Programming Interface ”. According to Wikipedia “API is an interface or communication protocol between a client and a server intended to simplify the building of client-side software. It has been described as a “contract” between the client and the server, such that if the client requests in a specific format, it will always get a response in a specific format or initiate a defined action.” That’s it, in a simple sentence we have to request on the Git Server with following some specific format of URL and as a result, Git Server will send us some data of specific format. Here we will receive a single JSON file. And that JSON file will contain our required data. Now if you are not familiar with JSON, take a look at this article about JSON from Medium here.

What’s the REST API?

REST API defines a set of functions which developers can perform requests and receive responses via HTTP protocol such as GET and POST.

GitHub API v3

For this article, we only need to use the HTTP GET method because our mission is to get some data. I won’t talk much about GitHub’s API because it will be much more complex and I just want to keep it simple. However, you can learn more about GitHub’s API from the official documentation here. And everything I will show you here is grabbed from the documentation that I mentioned.

Using the API

To use API we must need a programming language and don’t worry I will show the same thing using four different languages. Python, Java, Kotlin, and JavaScript. You can try this guide on other’s repository also. You just need to know the username & repository name but the only drawback here is you can try this only on the public repositories. And for example purpose, I will use one of my repository where I released an Android app named “GPA Calculator”. Repository link here.

Must need info of the repository

userName: “magpie-robins”

repoName: “gpa-calculator-android”

So, no more talking and let’s jump into the coding.


Python

You will need to install the “requests” module via pip or conda based on your environment.

Java

You will need to install the “json-simple” module with proper dependencies

Kotlin

You will need to install the “json-simple” module with proper dependencies

Javascript

You need to install nothing (Just Joking 😜)

Conclusion

I have kept my writing as simple as possible and the same goes for codes also. Hopefully, you’ve understood all that I discussed and don’t forget that I just showed a very small piece of GitHub API by accomplishing our goal. You can use these codes directly for your purpose’s but still, there is a lot to learn about. So, “Stay hungry. Stay foolish” as Steve Jobs said.

If you liked my writing you can inspire me by giving a Clap. You can follow me on Medium and I’m also available on Twitter here. Don’t forget to share your opinion on the comment section below.

If you like it, share it with others !
Leave a Reply

Your email address will not be published. Required fields are marked *