{"name":"@octokit/request","description":"Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node","version":"4.1.1","license":"MIT","source":"dist-src/index.js","types":"dist-types/index.d.ts","main":"dist-node/index.js","module":"dist-web/index.js","pika":true,"sideEffects":false,"keywords":["octokit","github","api","request"],"homepage":"https://github.com/octokit/request.js#readme","bugs":{"url":"https://github.com/octokit/request.js/issues"},"repository":{"type":"git","url":"git+https://github.com/octokit/request.js.git"},"dependencies":{"@octokit/endpoint":"^5.1.0","@octokit/request-error":"^1.0.1","deprecation":"^2.0.0","is-plain-object":"^3.0.0","node-fetch":"^2.3.0","once":"^1.4.0","universal-user-agent":"^2.1.0"},"devDependencies":{"@pika/pack":"^0.3.7","@pika/plugin-build-node":"^0.4.0","@pika/plugin-build-web":"^0.4.0","@pika/plugin-bundle-web":"^0.4.0","@pika/plugin-ts-standard-pkg":"^0.4.0","@types/fetch-mock":"^7.2.4","@types/jest":"^24.0.12","@types/node":"^12.0.3","@types/node-fetch":"^2.3.3","@types/once":"^1.4.0","fetch-mock":"^7.2.0","jest":"^24.7.1","pika-plugin-unpkg-field":"^1.1.0","prettier":"^1.17.0","semantic-release":"^15.10.5","semantic-release-plugin-update-version-in-files":"^1.0.0","ts-jest":"^24.0.2","typescript":"^3.4.5"},"publishConfig":{"access":"public","tag":"next"},"readme":"# request.js\n\n> Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node\n\n[![@latest](https://img.shields.io/npm/v/@octokit/request.svg)](https://www.npmjs.com/package/@octokit/request)\n[![Build Status](https://travis-ci.org/octokit/request.js.svg?branch=master)](https://travis-ci.org/octokit/request.js)\n[![Greenkeeper](https://badges.greenkeeper.io/octokit/request.js.svg)](https://greenkeeper.io/)\n\n`@octokit/request` is a request library for browsers & node that makes it easier\nto interact with [GitHub’s REST API](https://developer.github.com/v3/) and\n[GitHub’s GraphQL API](https://developer.github.com/v4/guides/forming-calls/#the-graphql-endpoint).\n\nIt uses [`@octokit/endpoint`](https://github.com/octokit/endpoint.js) to parse\nthe passed options and sends the request using [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)\n([node-fetch](https://github.com/bitinn/node-fetch) in Node).\n\n<!-- update table of contents by running `npx markdown-toc README.md -i` -->\n\n<!-- toc -->\n\n- [Features](#features)\n- [Usage](#usage)\n  - [REST API example](#rest-api-example)\n  - [GraphQL example](#graphql-example)\n  - [Alternative: pass `method` & `url` as part of options](#alternative-pass-method--url-as-part-of-options)\n- [request()](#request)\n- [`request.defaults()`](#requestdefaults)\n- [`request.endpoint`](#requestendpoint)\n- [Special cases](#special-cases)\n  - [The `data` parameter – set request body directly](#the-data-parameter-%E2%80%93-set-request-body-directly)\n  - [Set parameters for both the URL/query and the request body](#set-parameters-for-both-the-urlquery-and-the-request-body)\n- [LICENSE](#license)\n\n<!-- tocstop -->\n\n## Features\n\n🤩 1:1 mapping of REST API endpoint documentation, e.g. [Add labels to an issue](https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue) becomes\n\n```js\nrequest(\"POST /repos/:owner/:repo/issues/:number/labels\", {\n  headers: {\n    accept: \"application/vnd.github.symmetra-preview+json\"\n  },\n  owner: \"ocotkit\",\n  repo: \"request.js\",\n  number: 1,\n  labels: [\"🐛 bug\"]\n});\n```\n\n👍 Sensible defaults\n\n- `baseUrl`: `https://api.github.com`\n- `headers.accept`: `application/vnd.github.v3+json`\n- `headers.agent`: `octokit-request.js/<current version> <OS information>`, e.g. `octokit-request.js/1.2.3 Node.js/10.15.0 (macOS Mojave; x64)`\n\n👌 Simple to test: mock requests by passing a custom fetch method.\n\n🧐 Simple to debug: Sets `error.request` to request options causing the error (with redacted credentials).\n\n👶 Small bundle size (\\<5kb minified + gzipped)\n\n## Usage\n\n<table>\n<tbody valign=top align=left>\n<tr><th>\nBrowsers\n</th><td width=100%>\nLoad <code>@octokit/request</code> directly from <a href=\"https://cdn.pika.dev\">cdn.pika.dev</a>\n        \n```html\n<script type=\"module\">\nimport { request } from \"https://cdn.pika.dev/@octokit/request\";\n</script>\n```\n\n</td></tr>\n<tr><th>\nNode\n</th><td>\n\nInstall with <code>npm install @octokit/request</code>\n\n```js\nconst { request } = require(\"@octokit/request\");\n// or: import { request } from \"@octokit/request\";\n```\n\n</td></tr>\n</tbody>\n</table>\n\n### REST API example\n\n```js\n// Following GitHub docs formatting:\n// https://developer.github.com/v3/repos/#list-organization-repositories\nconst result = await request(\"GET /orgs/:org/repos\", {\n  headers: {\n    authorization: \"token 0000000000000000000000000000000000000001\"\n  },\n  org: \"octokit\",\n  type: \"private\"\n});\n\nconsole.log(`${result.data.length} repos found.`);\n```\n\n### GraphQL example\n\n```js\nconst result = await request(\"POST /graphql\", {\n  headers: {\n    authorization: \"token 0000000000000000000000000000000000000001\"\n  },\n  query: `query ($login: String!) {\n    organization(login: $login) {\n      repositories(privacy: PRIVATE) {\n        totalCount\n      }\n    }\n  }`,\n  variables: {\n    login: \"octokit\"\n  }\n});\n```\n\n### Alternative: pass `method` & `url` as part of options\n\nAlternatively, pass in a method and a url\n\n```js\nconst result = await request({\n  method: \"GET\",\n  url: \"/orgs/:org/repos\",\n  headers: {\n    authorization: \"token 0000000000000000000000000000000000000001\"\n  },\n  org: \"octokit\",\n  type: \"private\"\n});\n```\n\n## request()\n\n`request(route, options)` or `request(options)`.\n\n**Options**\n\n<table>\n  <thead>\n    <tr>\n      <th align=left>\n        name\n      </th>\n      <th align=left>\n        type\n      </th>\n      <th align=left>\n        description\n      </th>\n    </tr>\n  </thead>\n  <tr>\n    <th align=left>\n      <code>route</code>\n    </th>\n    <td>\n      String\n    </td>\n    <td>\n      If <code>route</code> is set it has to be a string consisting of the request method and URL, e.g. <code>GET /orgs/:org</code>\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.baseUrl</code>\n    </th>\n    <td>\n      String\n    </td>\n    <td>\n      <strong>Required.</strong> Any supported <a href=\"https://developer.github.com/v3/#http-verbs\">http verb</a>, case insensitive. <em>Defaults to <code>https://api.github.com</code></em>.\n    </td>\n  </tr>\n    <th align=left>\n      <code>options.headers</code>\n    </th>\n    <td>\n      Object\n    </td>\n    <td>\n      Custom headers. Passed headers are merged with defaults:<br>\n      <em><code>headers['user-agent']</code> defaults to <code>octokit-rest.js/1.2.3</code> (where <code>1.2.3</code> is the released version)</em>.<br>\n      <em><code>headers['accept']</code> defaults to <code>application/vnd.github.v3+json</code>.<br>\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.mediaType.format</code>\n    </th>\n    <td>\n      String\n    </td>\n    <td>\n      Media type param, such as `raw`, `html`, or `full`. See <a href=\"https://developer.github.com/v3/media/\">Media Types</a>.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.mediaType.previews</code>\n    </th>\n    <td>\n      Array of strings\n    </td>\n    <td>\n      Name of previews, such as `mercy`, `symmetra`, or `scarlet-witch`. See <a href=\"https://developer.github.com/v3/previews/\">API Previews</a>.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.method</code>\n    </th>\n    <td>\n      String\n    </td>\n    <td>\n      <strong>Required.</strong> Any supported <a href=\"https://developer.github.com/v3/#http-verbs\">http verb</a>, case insensitive. <em>Defaults to <code>Get</code></em>.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.url</code>\n    </th>\n    <td>\n      String\n    </td>\n    <td>\n      <strong>Required.</strong> A path or full URL which may contain <code>:variable</code> or <code>{variable}</code> placeholders,\n      e.g. <code>/orgs/:org/repos</code>. The <code>url</code> is parsed using <a href=\"https://github.com/bramstein/url-template\">url-template</a>.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.data</code>\n    </th>\n    <td>\n      Any\n    </td>\n    <td>\n      Set request body directly instead of setting it to JSON based on additional parameters. See <a href=\"#data-parameter\">\"The `data` parameter\"</a> below.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.request.agent</code>\n    </th>\n    <td>\n      <a href=\"https://nodejs.org/api/http.html#http_class_http_agent\">http(s).Agent</a> instance\n    </td>\n    <td>\n     Node only. Useful for custom proxy, certificate, or dns lookup.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.request.fetch</code>\n    </th>\n    <td>\n      Function\n    </td>\n    <td>\n     Custom replacement for <a href=\"https://github.com/bitinn/node-fetch\">built-in fetch method</a>. Useful for testing or request hooks.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.request.hook</code>\n    </th>\n    <td>\n      Function\n    </td>\n    <td>\n     Function with the signature <code>hook(endpointOptions, request)</code>, where <code>endpointOptions</code> are the parsed options as returned by <a href=\"https://github.com/octokit/endpoint.js#endpointmergeroute-options-or-endpointmergeoptions\"><code>endpoint.merge()</code></a>, and <code>request</code> is <a href=\"https://github.com/octokit/request.js#request\"><code>request()</code></a>. This option works great in conjuction with <a href=\"https://github.com/gr2m/before-after-hook\">before-after-hook</a>.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <a name=\"options-request-signal\"></a><code>options.request.signal</code>\n    </th>\n    <td>\n      <a href=\"https://github.com/bitinn/node-fetch/tree/e996bdab73baf996cf2dbf25643c8fe2698c3249#request-cancellation-with-abortsignal\">new AbortController().signal</a>\n    </td>\n    <td>\n      Use an <code>AbortController</code> instance to cancel a request. In node you can only cancel streamed requests.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.request.timeout</code>\n    </th>\n    <td>\n      Number\n    </td>\n    <td>\n     Node only. Request/response timeout in ms, it resets on redirect. 0 to disable (OS limit applies). <a href=\"#options-request-signal\">options.request.signal</a> is recommended instead.\n    </td>\n  </tr>\n</table>\n\nAll other options except `options.request.*` will be passed depending on the `method` and `url` options.\n\n1. If the option key is a placeholder in the `url`, it will be used as replacement. For example, if the passed options are `{url: '/orgs/:org/repos', org: 'foo'}` the returned `options.url` is `https://api.github.com/orgs/foo/repos`\n2. If the `method` is `GET` or `HEAD`, the option is passed as query parameter\n3. Otherwise the parameter is passed in the request body as JSON key.\n\n**Result**\n\n`request` returns a promise and resolves with 4 keys\n\n<table>\n  <thead>\n    <tr>\n      <th align=left>\n        key\n      </th>\n      <th align=left>\n        type\n      </th>\n      <th align=left>\n        description\n      </th>\n    </tr>\n  </thead>\n  <tr>\n    <th align=left><code>status</code></th>\n    <td>Integer</td>\n    <td>Response status status</td>\n  </tr>\n  <tr>\n    <th align=left><code>url</code></th>\n    <td>String</td>\n    <td>URL of response. If a request results in redirects, this is the final URL. You can send a <code>HEAD</code> request to retrieve it without loading the full response body.</td>\n  </tr>\n  <tr>\n    <th align=left><code>headers</code></th>\n    <td>Object</td>\n    <td>All response headers</td>\n  </tr>\n  <tr>\n    <th align=left><code>data</code></th>\n    <td>Any</td>\n    <td>The response body as returned from server. If the response is JSON then it will be parsed into an object</td>\n  </tr>\n</table>\n\nIf an error occurs, the `error` instance has additional properties to help with debugging\n\n- `error.status` The http response status code\n- `error.headers` The http response headers as an object\n- `error.request` The request options such as `method`, `url` and `data`\n\n## `request.defaults()`\n\nOverride or set default options. Example:\n\n```js\nconst myrequest = require(\"@octokit/request\").defaults({\n  baseUrl: \"https://github-enterprise.acme-inc.com/api/v3\",\n  headers: {\n    \"user-agent\": \"myApp/1.2.3\",\n    authorization: `token 0000000000000000000000000000000000000001`\n  },\n  org: \"my-project\",\n  per_page: 100\n});\n\nmyrequest(`GET /orgs/:org/repos`);\n```\n\nYou can call `.defaults()` again on the returned method, the defaults will cascade.\n\n```js\nconst myProjectRequest = request.defaults({\n  baseUrl: \"https://github-enterprise.acme-inc.com/api/v3\",\n  headers: {\n    \"user-agent\": \"myApp/1.2.3\"\n  },\n  org: \"my-project\"\n});\nconst myProjectRequestWithAuth = myProjectRequest.defaults({\n  headers: {\n    authorization: `token 0000000000000000000000000000000000000001`\n  }\n});\n```\n\n`myProjectRequest` now defaults the `baseUrl`, `headers['user-agent']`,\n`org` and `headers['authorization']` on top of `headers['accept']` that is set\nby the global default.\n\n## `request.endpoint`\n\nSee https://github.com/octokit/endpoint.js. Example\n\n```js\nconst options = request.endpoint(\"GET /orgs/:org/repos\", {\n  org: \"my-project\",\n  type: \"private\"\n});\n\n// {\n//   method: 'GET',\n//   url: 'https://api.github.com/orgs/my-project/repos?type=private',\n//   headers: {\n//     accept: 'application/vnd.github.v3+json',\n//     authorization: 'token 0000000000000000000000000000000000000001',\n//     'user-agent': 'octokit/endpoint.js v1.2.3'\n//   }\n// }\n```\n\nAll of the [`@octokit/endpoint`](https://github.com/octokit/endpoint.js) API can be used:\n\n- [`ocotkitRequest.endpoint()`](#endpoint)\n- [`ocotkitRequest.endpoint.defaults()`](#endpointdefaults)\n- [`ocotkitRequest.endpoint.merge()`](#endpointdefaults)\n- [`ocotkitRequest.endpoint.parse()`](#endpointmerge)\n\n## Special cases\n\n<a name=\"data-parameter\"></a>\n\n### The `data` parameter – set request body directly\n\nSome endpoints such as [Render a Markdown document in raw mode](https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode) don’t have parameters that are sent as request body keys, instead the request body needs to be set directly. In these cases, set the `data` parameter.\n\n```js\nconst options = endpoint(\"POST /markdown/raw\", {\n  data: \"Hello world github/linguist#1 **cool**, and #1!\",\n  headers: {\n    accept: \"text/html;charset=utf-8\",\n    \"content-type\": \"text/plain\"\n  }\n});\n\n// options is\n// {\n//   method: 'post',\n//   url: 'https://api.github.com/markdown/raw',\n//   headers: {\n//     accept: 'text/html;charset=utf-8',\n//     'content-type': 'text/plain',\n//     'user-agent': userAgent\n//   },\n//   body: 'Hello world github/linguist#1 **cool**, and #1!'\n// }\n```\n\n### Set parameters for both the URL/query and the request body\n\nThere are API endpoints that accept both query parameters as well as a body. In that case you need to add the query parameters as templates to `options.url`, as defined in the [RFC 6570 URI Template specification](https://tools.ietf.org/html/rfc6570).\n\nExample\n\n```js\nrequest(\n  \"POST https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}\",\n  {\n    name: \"example.zip\",\n    label: \"short description\",\n    headers: {\n      \"content-type\": \"text/plain\",\n      \"content-length\": 14,\n      authorization: `token 0000000000000000000000000000000000000001`\n    },\n    data: \"Hello, world!\"\n  }\n);\n```\n\n## LICENSE\n\n[MIT](LICENSE)\n","readmeFilename":"README.md","_id":"@octokit/request@4.1.1","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-LOyL0i3oxRo418EXRSJNk/3Q4I0/NKawTn6H/CQp+wnrG1UFLGu080gSsgnWobhPo5BpUNgSQ5BRk5FOOJhD1Q==","shasum":"614262214f48417b4d3b14e047d09a9c8e2f7a09","tarball":"http://registry-npm.ywwl.com/@octokit/request/download/@octokit/request-4.1.1.tgz","fileCount":17,"unpackedSize":33468,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdAzDrCRA9TVsSAnZWagAA4YoQAJHyNbgJWxQ9SsJS/3+b\nCxOtW3lfz0vNfuCg1aF98j2csqya0gUFIC3OaGSWnPsofrm4/eWkTboc6hxx\n/hmHqgiocwE71klXxKkk9u2oLe33Vo3Pq4f/t9NUS47+uBAGfILjMuhgESze\nbEb4bPLcmgypAps8rh8pLUtWnGnx4/qG/VwHQ5AP6tixjUnEIj+eeBgH2ie5\nnWRpblDCd31whSiFKhQXXiOyTvo1mEU25uQSzhuFfN+YnAOz+qWw2W4Mxp93\nx5Korjv1Zhx1rsEl09rMo1znt/l1uvXfRulYrwhm1p9eA87zDXLmfhnkEB6/\nZ+woGVN/VWS9wczo4y8WGeITyPZ+7Osy6QVkCALNKJngNzwNxk9qa31VSIIO\nZOO/cUXeSGwpbSKLA1Sdiv2XMwdn/6FSyKrTk3jckws01inGmI+HZGMz8Ud5\nHjUiy7vw7DYMrmFVzFiwEE57nkeF3d1r5nGkXwmATHTrr/zPNbe1CEFP4Sit\nS1KoKHfL5UjS+8Uz5eEyGMG/zontOwMPVfb0uTPz8VCMLsDbZPPzjIpiBTOs\n+A0U/fpGXP0Es6y+E0Bk51t6R0JLZkxjPuQghlWtS7GqO4zAd69Zv6qFnfOv\niuRox97DifEIuLPFDtMwKnccGqRvC4NomU7TJh6wX2JFiOVk/VofmqlPUOLc\nyBtT\r\n=YpSO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCgyqXu6iWDX70OoG/90mTI7QrI6oE5/VJ6v3Jdq1lezgIhAPNLywDBRK01Qp0iuFHl70ceaDOn5B3u8drEaKk9VjNP"}],"size":9430,"noattachment":false,"key":"/@octokit/request/-/@octokit/request-4.1.1.tgz"},"maintainers":[{"name":"bkeepers","email":"brandon@opensoul.org"},{"name":"gr2m","email":"gregor@martynus.net"},{"name":"octokitbot","email":"octokitbot@martynus.net"}],"_npmUser":{"name":"octokitbot","email":"octokitbot@martynus.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/request_4.1.1_1560490218696_0.04160341884498364"},"_hasShrinkwrap":false,"publish_time":1560490218904,"_cnpm_publish_time":1560490218904,"dist-tags":{"beta":"9.0.0-beta.1","latest":"10.0.16","release-6.x":"6.2.8","release-8.x":"8.4.1","release-9.x":"9.2.4"}}