Search code

GET {{baseUrl}}/search/code?q=<string>&sort=<string>&order=desc&per_page=30&page=1

Searches for query terms inside of a file. This method returns up to 100 results per page.

When searching for code, you can get text match metadata for the file content and file path fields when you pass the text-match media type. For more details about how to receive highlighted search results, see Text match metadata.

For example, if you want to find the definition of the addClass function inside jQuery repository, your query would look something like this:

q=addClass+in:file+language:js+repo:jquery/jquery

This query searches for the keyword addClass within a file's contents. The query limits the search to files where the language is JavaScript in the jquery/jquery repository.

Due to the complexity of searching code, there are a few restrictions on how searches are performed:

  • Only the default branch is considered. In most cases, this will be the master branch.
  • Only files smaller than 384 KB are searchable.
  • You must always include at least one search term when searching source code. For example, searching for language:go is not valid, while amazing language:go is.

Request Params

KeyDatatypeRequiredDescription
qstring(Required) The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see Constructing a search query. See "Searching code" for a detailed list of qualifiers.
sortstringSorts the results of your query. Can only be indexed, which indicates how recently a file has been indexed by the GitHub search infrastructure. Default: best match
orderstringDetermines whether the first search result returned is the highest number of matches (desc) or lowest number of matches (asc). This parameter is ignored unless you provide sort.
per_pagenumberResults per page (max 100)
pagenumberPage number of the results to fetch.

RESPONSES

status: OK

{&quot;total_count&quot;:7,&quot;incomplete_results&quot;:false,&quot;items&quot;:[{&quot;name&quot;:&quot;classes.js&quot;,&quot;path&quot;:&quot;src/attributes/classes.js&quot;,&quot;sha&quot;:&quot;d7212f9dee2dcc18f084d7df8f417b80846ded5a&quot;,&quot;url&quot;:&quot;https://api.github.com/repositories/167174/contents/src/attributes/classes.js?ref=825ac3773694e0cd23ee74895fd5aeb535b27da4&quot;,&quot;git_url&quot;:&quot;https://api.github.com/repositories/167174/git/blobs/d7212f9dee2dcc18f084d7df8f417b80846ded5a&quot;,&quot;html_url&quot;:&quot;https://github.com/jquery/jquery/blob/825ac3773694e0cd23ee74895fd5aeb535b27da4/src/attributes/classes.js&quot;,&quot;repository&quot;:{&quot;id&quot;:167174,&quot;node_id&quot;:&quot;MDEwOlJlcG9zaXRvcnkxNjcxNzQ=&quot;,&quot;name&quot;:&quot;jquery&quot;,&quot;full_name&quot;:&quot;jquery/jquery&quot;,&quot;owner&quot;:{&quot;login&quot;:&quot;jquery&quot;,&quot;id&quot;:70142,&quot;node_id&quot;:&quot;MDQ6VXNlcjcwMTQy&quot;,&quot;avatar_url&quot;:&quot;https://0.gravatar.com/avatar/6906f317a4733f4379b06c32229ef02f?d=https%3A%2F%2Fidenticons.github.com%2Ff426f04f2f9813718fb806b30e0093de.png&quot;,&quot;gravatar_id&quot;:&quot;&quot;,&quot;url&quot;:&quot;https://api.github.com/users/jquery&quot;,&quot;html_url&quot;:&quot;https://github.com/jquery&quot;,&quot;followers_url&quot;:&quot;https://api.github.com/users/jquery/followers&quot;,&quot;following_url&quot;:&quot;https://api.github.com/users/jquery/following{/other_user}&quot;,&quot;gists_url&quot;:&quot;https://api.github.com/users/jquery/gists{/gist_id}&quot;,&quot;starred_url&quot;:&quot;https://api.github.com/users/jquery/starred{/owner}{/repo}&quot;,&quot;subscriptions_url&quot;:&quot;https://api.github.com/users/jquery/subscriptions&quot;,&quot;organizations_url&quot;:&quot;https://api.github.com/users/jquery/orgs&quot;,&quot;repos_url&quot;:&quot;https://api.github.com/users/jquery/repos&quot;,&quot;events_url&quot;:&quot;https://api.github.com/users/jquery/events{/privacy}&quot;,&quot;received_events_url&quot;:&quot;https://api.github.com/users/jquery/received_events&quot;,&quot;type&quot;:&quot;Organization&quot;,&quot;site_admin&quot;:false},&quot;private&quot;:false,&quot;html_url&quot;:&quot;https://github.com/jquery/jquery&quot;,&quot;description&quot;:&quot;jQuery JavaScript Library&quot;,&quot;fork&quot;:false,&quot;url&quot;:&quot;https://api.github.com/repos/jquery/jquery&quot;,&quot;forks_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/forks&quot;,&quot;keys_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/keys{/key_id}&quot;,&quot;collaborators_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/collaborators{/collaborator}&quot;,&quot;teams_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/teams&quot;,&quot;hooks_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/hooks&quot;,&quot;issue_events_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/issues/events{/number}&quot;,&quot;events_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/events&quot;,&quot;assignees_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/assignees{/user}&quot;,&quot;branches_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/branches{/branch}&quot;,&quot;tags_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/tags&quot;,&quot;blobs_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/git/blobs{/sha}&quot;,&quot;git_tags_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/git/tags{/sha}&quot;,&quot;git_refs_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/git/refs{/sha}&quot;,&quot;trees_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/git/trees{/sha}&quot;,&quot;statuses_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/statuses/{sha}&quot;,&quot;languages_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/languages&quot;,&quot;stargazers_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/stargazers&quot;,&quot;contributors_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/contributors&quot;,&quot;subscribers_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/subscribers&quot;,&quot;subscription_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/subscription&quot;,&quot;commits_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/commits{/sha}&quot;,&quot;git_commits_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/git/commits{/sha}&quot;,&quot;comments_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/comments{/number}&quot;,&quot;issue_comment_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/issues/comments/{number}&quot;,&quot;contents_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/contents/{+path}&quot;,&quot;compare_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/compare/{base}...{head}&quot;,&quot;merges_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/merges&quot;,&quot;archive_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/{archive_format}{/ref}&quot;,&quot;downloads_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/downloads&quot;,&quot;issues_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/issues{/number}&quot;,&quot;pulls_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/pulls{/number}&quot;,&quot;milestones_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/milestones{/number}&quot;,&quot;notifications_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/notifications{?since,all,participating}&quot;,&quot;labels_url&quot;:&quot;https://api.github.com/repos/jquery/jquery/labels{/name}&quot;,&quot;deployments_url&quot;:&quot;http://api.github.com/repos/octocat/Hello-World/deployments&quot;,&quot;releases_url&quot;:&quot;http://api.github.com/repos/octocat/Hello-World/releases{/id}&quot;},&quot;score&quot;:1}]}