Search code examples
githubgithub-api

How to filter and fetch GitHub repositories by topics


I wanted to fetch GitHub repositories that come under a certain topic from the GitHub API.

For e.g. I fetch all repos using https://api.github.com/repositories. And I fetch a topic by using https://api.github.com/search/topics?q=<TOPIC_NAME>.

But I want to fetch repositories that come under a topic. Let's say for JavaScript: https://github.com/topics/javascript

All the repos that are on this webpage is what I want to fetch using GitHub API. Is there a way I can do that?


Solution

  • Try this API URL:

    const url = `https://api.github.com/search/repositories?q=topic:${TOPIC}`
    

    curl request for the same if you are using any API client:

    curl --request GET \
      --url 'https://api.github.com/search/repositories?q=topic%3Ajavascript' \
      --header 'accept: application/vnd.github.mercy-preview+json'