How to get the search results code number in GitHub with GitHub API?

225 Views Asked by At

I have the following search term

navigator.geolocation.getCurrentPosition

which return 271,769 code results, how I can return the code results number by using github API

1

There are 1 best solutions below

0
Matt On

You can use the GitHub Search API to search code. More precisely, the following endpoint:

[GET] /search/code

Since you are only interested in the total number, you can set the per_page parameter to 1 in order to make the the result smaller. The number of results is returned in the response as total_count:

{
  "total_count": 435249,
  "incomplete_results": false,
  "items": [
    ...
  ]
}

Example using the GitHub command line tool:

gh api -X GET search/code -f q='navigator.geolocation.getCurrentPosition' -f per_page='1'