{"id":15643062,"url":"https://github.com/jonschlinkert/github-base","last_synced_at":"2025-04-14T16:34:21.959Z","repository":{"id":29633087,"uuid":"33174143","full_name":"jonschlinkert/github-base","owner":"jonschlinkert","description":"Simple, opinionated node.js interface for creating basic apps with the GitHub API.","archived":false,"fork":false,"pushed_at":"2018-08-14T16:45:42.000Z","size":104,"stargazers_count":61,"open_issues_count":0,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T05:13:12.059Z","etag":null,"topics":["api","axios","get","github","got","javascript","needle","node","request","url"],"latest_commit_sha":null,"homepage":"http://jonschlinkert.github.io/github-base","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/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-31T08:34:10.000Z","updated_at":"2025-02-15T03:24:02.000Z","dependencies_parsed_at":"2022-09-03T15:23:15.018Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/github-base","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fgithub-base","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fgithub-base/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fgithub-base/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fgithub-base/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/github-base/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248917048,"owners_count":21182918,"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":["api","axios","get","github","got","javascript","needle","node","request","url"],"created_at":"2024-10-03T11:58:46.526Z","updated_at":"2025-04-14T16:34:21.937Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","readme":"# github-base [![NPM version](https://img.shields.io/npm/v/github-base.svg?style=flat)](https://www.npmjs.com/package/github-base) [![NPM monthly downloads](https://img.shields.io/npm/dm/github-base.svg?style=flat)](https://npmjs.org/package/github-base) [![NPM total downloads](https://img.shields.io/npm/dt/github-base.svg?style=flat)](https://npmjs.org/package/github-base) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/github-base.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/github-base) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/github-base.svg?style=flat\u0026label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/github-base)\n\n\u003e Low-level methods for working with the GitHub API in node.js/JavaScript.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Table of Contents\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eDetails\u003c/strong\u003e\u003c/summary\u003e\n\n- [Install](#install)\n- [Heads up!](#heads-up)\n- [Why github-base, instead of...?](#why-github-base-instead-of)\n- [Usage](#usage)\n- [API](#api)\n  * [GitHub](#github)\n  * [.request](#request)\n  * [.get](#get)\n  * [.delete](#delete)\n  * [.patch](#patch)\n  * [.post](#post)\n  * [.put](#put)\n  * [.paged](#paged)\n  * [.use](#use)\n- [Authentication](#authentication)\n- [Paths and placeholders](#paths-and-placeholders)\n- [Options](#options)\n  * [options.query](#optionsquery)\n- [About](#about)\n  * [Related projects](#related-projects)\n  * [Contributors](#contributors)\n  * [Author](#author)\n  * [License](#license)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_\n\n\u003c/details\u003e\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save github-base\n```\n\n## Heads up!\n\nAs of v1.0, the API is 100% promise based, callbacks are no longer supported. Please see the [API documentation](#API) and [release history](changelog.md) for more details.\n\n## Why github-base, instead of...?\n\nEvery other GitHub API library we found either had a [huge dependency tree](https://github.com/sindresorhus/gh-got), tries to be [everything to everyone](https://github.com/michael/github/blob/master/package.json#L45-L56), was [too bloated with boilerplace code](https://github.com/mikedeboer/node-github/tree/master/templates), was too opinionated, or was not maintained.\n\nWe created github-base to provide low-level support for a handful of HTTP verbs for creating higher-level libraries:\n\n* [.request](#request): the base handler all of the GitHub HTTP verbs: `GET`, `PUT`, `POST`, `DELETE`, `PATCH`\n* [.get](#get): proxy for `.request('GET', path, options, cb)`\n* [.delete](#delete): proxy for `.request('DELETE', path, options, cb)`\n* [.patch](#patch): proxy for `.request('PATCH', path, options, cb)`\n* [.post](#post): proxy for `.request('POST', path, options, cb)`\n* [.put](#put): proxy for `.request('PUT', path, options, cb)`\n* [.paged](#paged): recursively makes `GET` requests until all pages have been retrieved.\n\nJump to the [API section](#API) for more details.\n\n## Usage\n\nAdd github-base to your node.js/JavaScript project with the following line of code:\n\n```js\nconst GitHub = require('github-base');\n```\n\n**Example usage**\n\nRecursively `GET` all pages of gists for a user:\n\n```js\nconst github = new GitHub({ /* options */ });\nconst owner = 'jonschlinkert';\n\ngithub.paged(`/users/${owner}/gists`)\n  .then(res =\u003e console.log(res))\n  .catch(console.error);\n```\n\n## API\n\n_(All request methods take a callback, or return a promise if a callback isn't passed as the last argument)_.\n\n### [GitHub](index.js#L18)\n\nCreate an instance of `GitHub` with the given options.\n\n**Params**\n\n* `options` **{Object}**\n\n**Example**\n\n```js\nconst GitHub = require('github-base');\nconst github = new GitHub([options]);\n```\n\n### [.request](index.js#L42)\n\nUses [needle](https://github.com/tomas/needle) to make a request to the GitHub API. Supports the following verbs: `GET`, `PUT`, `POST`, `PATCH`, and `DELETE`. Takes a callback or returns a promise.\n\n**Params**\n\n* `method` **{String}**: The http VERB to use\n* `path` **{String}**: The path to append to the base GitHub API URL.\n* `options` **{Options}**: Request [options](#options).\n\n**Example**\n\n```js\n// list all orgs for the authenticated user\nconst auth = require('./local-private-auth-info');\nconst github = new GitHub(auth);\ngithub.request('GET', '/user/orgs')\n  .then(res =\u003e console.log(res.body));\n```\n\n### [.get](index.js#L64)\n\nMake a `GET` request to the GitHub API.\n\n**Params**\n\n* `path` **{String}**: The path to append to the base GitHub API URL.\n* `options` **{Options}**: Request [options](#options).\n\n**Example**\n\n```js\n// get a list of orgs for the authenticated user\ngithub.get('/user/orgs')\n  .then(res =\u003e console.log(res.body));\n\n// get gists for the authenticated user\ngithub.get('/gists')\n  .then(res =\u003e console.log(res.body));\n```\n\n### [.delete](index.js#L84)\n\nMake a `DELETE` request to the GitHub API.\n\n**Params**\n\n* `path` **{String}**: The path to append to the base GitHub API URL.\n* `options` **{Options}**: Request [options](#options).\n\n**Example**\n\n```js\n// un-follow someone\ngithub.delete('/user/following/:some_username', { some_username: 'whatever' })\n  .then(res =\u003e {\n    console.log('RESPONSE:', res);\n  });\n```\n\n### [.patch](index.js#L106)\n\nMake a `PATCH` request to the GitHub API.\n\n**Params**\n\n* `path` **{String}**: The path to append to the base GitHub API URL.\n* `options` **{Options}**: Request [options](#options).\n\n**Example**\n\n```js\n// update a gist\nconst fs = require('fs');\nconst options = { files: { 'readme.md': { content: fs.readFileSync('README.md', 'utf8') } } };\ngithub.patch('/gists/bd139161a425896f35f8', options)\n  .then(res =\u003e {\n    console.log('RESPONSE:', res);\n  });\n```\n\n### [.post](index.js#L126)\n\nMake a `POST` request to the GitHub API.\n\n**Params**\n\n* `path` **{String}**: The path to append to the base GitHub API URL.\n* `options` **{Options}**: Request [options](#options).\n\n**Example**\n\n```js\n// create a new repository\ngithub.post('/user/repos', { name: 'new-repo-name' })\n  .then(res =\u003e {\n    console.log('RESPONSE:', res);\n  });\n```\n\n### [.put](index.js#L146)\n\nMake a `PUT` request to the GitHub API.\n\n**Params**\n\n* `path` **{String}**: The path to append to the base GitHub API URL.\n* `options` **{Options}**: Request [options](#options).\n\n**Example**\n\n```js\n// follow someone\ngithub.put('/user/following/jonschlinkert')\n  .then(res =\u003e {\n    console.log('RESPONSE:', res);\n  });\n```\n\n### [.paged](index.js#L165)\n\nRecursively make GET requests until all pages of records are returned.\n\n**Params**\n\n* `path` **{String}**: The path to append to the base GitHub API URL.\n* `options` **{Options}**: Request [options](#options).\n\n**Example**\n\n```js\n// get all repos for the authenticated user\ngithub.paged('/user/repos?type=all\u0026per_page=1000\u0026sort=updated')\n  .then(res =\u003e console.log(res.pages))\n  .catch(console.error)\n```\n\n### .use\n\nRegister plugins with [use](https://github.com/jonschlinkert/use).\n\n```js\nconst github = new GitHub();\n\ngithub.use(function() {\n  // do stuff with the github-base instance\n});\n```\n\n## Authentication\n\nThere are a few ways to authenticate, all of them require info to be passed on the [options](#options).\n\n```js\nconst github = new GitHub({\n  username: YOUR_USERNAME,\n  password: YOUR_PASSWORD,\n});\n\n// or \nconst github = new GitHub({\n  token: YOUR_TOKEN\n});\n\n// or \nconst github = new GitHub({\n  bearer: YOUR_JSON_WEB_TOKEN\n});\n```\n\n## Paths and placeholders\n\n**Deprecated**: Since es2015 templates make this feature less useful, we plan to remove it in a future release.\n\nPaths are similar to router paths, where placeholders in the given string are replaced with values from the options. For instance, the path in the following example:\n\n```js\nconst github = new GitHub();\nconst options = { user: 'jonschlinkert', repo: 'github-base', subscribed: true };\n\ngithub.put('/repos/:user/:repo/subscription', options);\n```\n\nExpands to:\n\n```js\n'/repos/jonschlinkert/github-base/subscription'\n```\n\nPlaceholder names are also arbitrary, you can make them whatever you want as long as all placeholder names can be resolved using values defined on the options.\n\n## Options\n\nOptions may be passed to the constructor when instantiating, and/or set on the instance directly, and/or passed to any of the methods.\n\n**Examples**\n\n```js\n// pass to constructor\nconst github = new GitHub({ user: 'doowb' });\n\n// and/or directly set on instance options\ngithub.options.user = 'doowb';\n\n// and/or pass to a method\ngithub.get('/users/:user/gists', { user: 'doowb' })\n```\n\n### options.query\n\n**Type**: `object`\n\n**Default**: `{ per_page: 100 }` for [get](#get) and [paged](#paged) requests, `undefined` for all other requests.\n\nPass an object to stringify and append to the URL using the `.stringify` method from [qs](https://github.com/ljharb/qs).\n\n**Examples**\n\n```js\ngithub.paged('/users/:user/gists', { user: 'doowb', query: { per_page: 30 } })\n  .then(res =\u003e {\n    console.log(res.pages);\n  });\n```\n\nYou can also manually append the query string:\n\n```js\ngithub.paged('/users/:user/gists?per_page=30', { user: 'doowb' })\n  .then(res =\u003e {\n    console.log(res.pages);\n  });\n```\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [gists](https://www.npmjs.com/package/gists): Methods for working with the GitHub Gist API. Node.js/JavaScript | [homepage](https://github.com/jonschlinkert/gists \"Methods for working with the GitHub Gist API. Node.js/JavaScript\")\n* [github-contributors](https://www.npmjs.com/package/github-contributors): Generate a markdown or JSON list of contributors for a project using the GitHub API. | [homepage](https://github.com/jonschlinkert/github-contributors \"Generate a markdown or JSON list of contributors for a project using the GitHub API.\")\n* [repos](https://www.npmjs.com/package/repos): List all repositories for one or more users or orgs. | [homepage](https://github.com/jonschlinkert/repos \"List all repositories for one or more users or orgs.\")\n* [topics](https://www.npmjs.com/package/topics): Get and update GitHub repository topics. | [homepage](https://github.com/jonschlinkert/topics \"Get and update GitHub repository topics.\")\n\n### Contributors\n\n| **Commits** | **Contributor** | \n| --- | --- |\n| 40 | [jonschlinkert](https://github.com/jonschlinkert) |\n| 10 | [doowb](https://github.com/doowb) |\n| 7 | [olstenlarck](https://github.com/olstenlarck) |\n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 14, 2018._","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fgithub-base","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fgithub-base","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fgithub-base/lists"}