How can I know the number of repository by user name?

I want to make a name search using rxswift and print the number of repository.

However, “https://api.github.com/search/users” does not include the number of repository.

Of course, I can call the api once more with the correct ID, but if there are many search results, I will be limited.

How should I do it?

It sounds like you’re trying to get the number of public repositories for users with a name matching some sort of search string? And if you don’t exactly match a user name, you want to get the number of public repositories for all users matching that search string?

If that is the case, then you’re going to have to work with the rate limiting system. You can search for users that match the search string, then use the List user repositories endpoint to get a list of each users’ repos, and count them. For large sets of results, you’ll need to keep an eye on the rate limiting and pause when the limit approaches.

Let me know if I’ve misunderstood.

Hey @byunsangjin!

To build on what @lee-dohm said, there are a few tricks depending on the exact information you’re looking for. 

Using the REST API, you can do some math with a HEAD request to GET /users/:username/repos to find out the exact number of Repositories the user has that are visible to you, with something like this:

curl -I 'https://api.github.com/users/nickvanw/repos?per_page=1'

That will return a pagination header:

Link: <https://api.github.com/user/1907071/repos?per_page=1&page=2>; rel="next", <https://api.github.com/user/1907071/repos?per_page=1&page=27>; rel="last"

Which will tell you that I have 27 Repositories that are public (as I made this request anonymously).

Alternatively, the GraphQL API could be used as well, with a query that looks like this:

query {
  user(login: "nickvanw") {
    repositories {
      totalCount
    }
  }
}

This will return the total count of repositories (again, that are visible to you) for that user. 

Let me know if this is helpful, or if it’s not quite what you are looking for!

1 Like

https://api.github.com/users/<username, e.g. hasherezade>

{
...
  "public_repos": 53,
...
}