{"id":13895278,"url":"https://github.com/gr2m/octokit-rest-plugin-example","last_synced_at":"2025-07-17T10:33:23.266Z","repository":{"id":57313388,"uuid":"120823131","full_name":"gr2m/octokit-rest-plugin-example","owner":"gr2m","description":"@octokit/rest plugin example","archived":true,"fork":false,"pushed_at":"2021-03-05T06:48:28.000Z","size":7,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-13T22:24:01.600Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/gr2m.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-08T21:59:22.000Z","updated_at":"2024-03-21T18:28:35.000Z","dependencies_parsed_at":"2022-09-13T03:01:17.246Z","dependency_job_id":null,"html_url":"https://github.com/gr2m/octokit-rest-plugin-example","commit_stats":null,"previous_names":["gr2m/octokit-rest-plugin-exmple"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr2m%2Foctokit-rest-plugin-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr2m%2Foctokit-rest-plugin-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr2m%2Foctokit-rest-plugin-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr2m%2Foctokit-rest-plugin-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gr2m","download_url":"https://codeload.github.com/gr2m/octokit-rest-plugin-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225808641,"owners_count":17527414,"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":[],"created_at":"2024-08-06T18:02:06.264Z","updated_at":"2024-11-25T00:31:19.999Z","avatar_url":"https://github.com/gr2m.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# @octokit/rest plugin example\n\n[`@octokit/rest`](https://github.com/octokit/rest.js) has an [experimental plugin API](https://github.com/octokit/rest.js/tree/master/lib/plugins). A plugin can\nbe shared as npm module.\n\nThe [example plugin](index.js) from this repository adds a new `octokit.root()`\nmethod which sends a get request to the [root endpoint](https://developer.github.com/v3/#root-endpoint)\n\n```js\nconst octokit = require('@octokit/rest')()\noctokit.plugin(require('octokit-rest-plugin-example'))\n\noctokit.root().then({data} =\u003e {\n  // data from response\n})\n```\n\n## How to add new methods to octokit using plugins\n\nIn order to add a new method to `octokit`, a plugin can look like this\n\n```js\nmodule.exports = function helloWorldPlugin(octokit) {\n  // add .helloWorld method to `octokit` instance\n  octokit.helloWorld = function () {\n    console.log('Hello, world!')\n  }\n}\n```\n\nTo add a method for a new GitHub API endpoint, a plugin can look like this\n\n```js\nmodule.exports = function newEndpointsPlugin(octokit) {\n  // add .helloWorld method to `octokit` instance\n  octokit.repos.myNewEndpoint = function (options) {\n    return octokit.request({\n      method: 'POST',\n      url: '/repos/:owner/:repo/something-new',\n      headers: {\n        accept: 'application/vnd.github.black-panther-preview+json'\n      },\n      ...options\n    })\n  }\n}\n```\n\nThe method can then be used like this\n\n```js\nconst octokit = require('@octokit/rest')()\noctokit.plugin(require('octokit-rest-new-endpoints-plugin'))\noctokit.repos.myNewEndpoint({\n  owner: 'octokit',\n  repo: 'welcome',\n  foo: 'bar'\n})\n```\n\nIf there are many new endpoints it could be worth to create a [`routes.json file like @octokit/rest/lib/routes.json`](https://github.com/octokit/rest.js/blob/master/lib/routes.json)\nand then build the endpoints based on that file like the core [endpoint-methods plugin](https://github.com/octokit/rest.js/tree/master/lib/plugins/endpoint-methods).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgr2m%2Foctokit-rest-plugin-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgr2m%2Foctokit-rest-plugin-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgr2m%2Foctokit-rest-plugin-example/lists"}