Home > front end >  Github rest api do not return correct list of data
Github rest api do not return correct list of data

Time:03-09

I am trying to get the top 10 repositories based on the star, So here is the API I am using.

However, The result I get is incorrect and it seems like it changes the order of the top 3 repositories. For example: The first time I call the below API, here is the top 3 repository based on the star.

  1. freeCodeCamp/freeCodeCamp 342K
  2. EbookFoundation/free-programming-books 225K
  3. vuejs/vue 194K

After 1 minute, i call the api one more time and got totally different result:

  1. freeCodeCamp/freeCodeCamp 342K
  2. 996icu/996.ICU 261K
  3. jwasham/coding-interview-university 212K

So basically, the result is not correct. Is there anything wrong with my API endpoint?

https://api.github.com/search/repositories?q=stars:>0&sort=stars&per_page=3

CodePudding user response:

I modified the api little bit ,

https://api.github.com/search/repositories?q=stars:>=10000&sort=stars&order=desc

and I am getting consistent results like this;

1.freeCodeCamp/freeCodeCamp 
2. 996icu/996.ICU
3. free-programming-books

CodePudding user response:

The GitHub website lists the top repositories under https://github.com/search?q=stars:>1&s=stars&type=Repositories as:

  1. freeCodeCamp/freeCodeCamp
  2. 996icu/996.ICU
  3. EbookFoundation/free-programming-books

First of all, this should be the right endpoint, see https://docs.github.com/en/rest/reference/search#search-repositories, the page says:

The results are sorted by stars in descending order, so that the most popular repositories appear first in the search results.

I get the same result when I use the parameters and run the following query in the browser, using the same parameters as on the website above:

https://api.github.com/search/repositories?q=stars:>1&s=stars

Note: I am not sure about the s parameter. Either s is short for sort or it is not used as the result is already sorted.

  • Related