{"id":13527415,"url":"https://github.com/sindresorhus/gh-got","last_synced_at":"2025-05-16T16:08:07.684Z","repository":{"id":30654372,"uuid":"34210019","full_name":"sindresorhus/gh-got","owner":"sindresorhus","description":"Convenience wrapper for Got to interact with the GitHub API","archived":false,"fork":false,"pushed_at":"2022-10-27T08:54:45.000Z","size":75,"stargazers_count":177,"open_issues_count":1,"forks_count":23,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-07T17:22:52.582Z","etag":null,"topics":["github","github-api","got","http-client","node-module","npm-package"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2015-04-19T14:33:47.000Z","updated_at":"2025-04-22T20:27:10.000Z","dependencies_parsed_at":"2022-08-24T16:52:08.634Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/gh-got","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgh-got","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgh-got/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgh-got/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fgh-got/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/gh-got/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254529386,"owners_count":22086430,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github","github-api","got","http-client","node-module","npm-package"],"created_at":"2024-08-01T06:01:47.541Z","updated_at":"2025-05-16T16:08:07.641Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# gh-got\n\n\u003e Convenience wrapper for [Got](https://github.com/sindresorhus/got) to interact with the [GitHub API](https://developer.github.com/v3/)\n\nUnless you're already using Got, you should probably use GitHub's own [@octokit/rest.js](https://github.com/octokit/rest.js) or [@octokit/graphql.js](https://github.com/octokit/graphql.js) packages instead.\n\n## Install\n\n```sh\nnpm install gh-got\n```\n\n## Usage\n\nInstead of:\n\n```js\nimport got from 'got';\n\nconst token = 'foo';\n\nconst {body} = await got('https://api.github.com/users/sindresorhus', {\n\tjson: true,\n\theaders: {\n\t\t'accept': 'application/vnd.github.v3+json',\n\t\t'authorization': `token ${token}`\n\t}\n});\n\nconsole.log(body.login);\n//=\u003e 'sindresorhus'\n```\n\nYou can do:\n\n```js\nimport ghGot from 'gh-got';\n\nconst {body} = await ghGot('users/sindresorhus', {\n\tcontext: {\n\t\ttoken: 'foo'\n\t}\n});\n\nconsole.log(body.login);\n//=\u003e 'sindresorhus'\n```\n\nOr:\n\n```js\nimport ghGot from 'gh-got';\n\nconst {body} = await ghGot('https://api.github.com/users/sindresorhus', {\n\tcontext: {\n\t\ttoken: 'foo'\n\t}\n});\n\nconsole.log(body.login);\n//=\u003e 'sindresorhus'\n```\n\n## API\n\nSame API as [`got`](https://github.com/sindresorhus/got), including options, the stream API, aliases, pagination, etc, but with some additional options below.\n\nErrors are improved by using the custom GitHub error messages. Doesn't apply to the stream API.\n\n### `gh-got` specific options\n\n#### token\n\nType: `string`\n\nGitHub [access token](https://github.com/settings/tokens/new).\n\nCan be set globally with the `GITHUB_TOKEN` environment variable.\n\n#### prefixUrl\n\nType: `string`\\\nDefault: `https://api.github.com/`\n\nTo support [GitHub Enterprise](https://enterprise.github.com).\n\nCan be set globally with the `GITHUB_ENDPOINT` environment variable.\n\n#### body\n\nType: `object`\n\nCan be specified as a plain object and will be serialized as JSON with the appropriate headers set.\n\n## Rate limit\n\nResponses and errors have a `.rateLimit` property with info about the current [rate limit](https://developer.github.com/v3/#rate-limiting). *(This is not yet implemented for the stream API)*\n\n```js\nimport ghGot from 'gh-got';\n\nconst {rateLimit} = await ghGot('users/sindresorhus');\n\nconsole.log(rateLimit);\n//=\u003e {limit: 5000, remaining: 4899, reset: [Date 2018-12-31T20:45:20.000Z]}\n```\n\n## Authorization\n\nAuthorization for GitHub uses the following logic:\n\n1. If `options.headers.authorization` is passed to `gh-got`, then this will be used as first preference.\n2. If `options.token` is provided, then the `authorization` header will be set to `token \u003coptions.token\u003e`.\n3. If `options.headers.authorization` and `options.token` are not provided, then the `authorization` header will be set to `token \u003cprocess.env.GITHUB_TOKEN\u003e`\n\nIn most cases, this means you can simply set `GITHUB_TOKEN`, but it also allows it to be overridden by setting `options.token` or `options.headers.authorization` explicitly. For example, if [authenticating as a GitHub App](https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app), you could do the following:\n\n```js\nimport ghGot from 'gh-got';\n\nconst options = {\n\theaders: {\n\t\tauthorization: `Bearer ${jwt}`\n\t}\n};\nconst {body} = await ghGot('app', options);\n\nconsole.log(body.name);\n//=\u003e 'MyApp'\n```\n\n## Pagination\n\nSee the [Got docs](https://github.com/sindresorhus/got/blob/main/documentation/4-pagination.md).\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Repository","Packages","包","目录","JavaScript","HTTP","Uncategorized"],"sub_categories":["HTTP","Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fgh-got","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fgh-got","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fgh-got/lists"}