Skip to content

Commit

Permalink
feat: set all REST API endpoint methods on octokit.rest.*. The meth…
Browse files Browse the repository at this point in the history
…ods are also set on `octokit.*` for foreseeable time, but no longer documented, and will be deprecated at some point in future (#2054)
  • Loading branch information
renovate[bot] authored Mar 26, 2021
1 parent 5350388 commit 40ee966
Show file tree
Hide file tree
Showing 50 changed files with 1,069 additions and 631 deletions.
4 changes: 2 additions & 2 deletions HOW_IT_WORKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## Endpoint options (① - ④)

`@octokit/rest` exposes a method for each [REST API endpoint](https://docs.github.com/en/rest/reference/), for example `octokit.repos.listForOrg()` for [`GET /orgs/{org}/repos`](https://docs.github.com/en/rest/reference/repos/#list-organization-repositories). The methods are generated in [`@octokit/plugin-rest-endpoint-methods`](https://github.com/octokit/plugin-rest-endpoint-methods.js/). The [`src/generated/endpoints.ts` file](https://github.com/octokit/plugin-rest-endpoint-methods.js/blob/master/src/generated/endpoints.ts) defines the **② endpoint default options** `method`, `url`, and in some cases `mediaType` and `headers`.
`@octokit/rest` exposes a method for each [REST API endpoint](https://docs.github.com/en/rest/reference/), for example `octokit.rest.repos.listForOrg()` for [`GET /orgs/{org}/repos`](https://docs.github.com/en/rest/reference/repos/#list-organization-repositories). The methods are generated in [`@octokit/plugin-rest-endpoint-methods`](https://github.com/octokit/plugin-rest-endpoint-methods.js/). The [`src/generated/endpoints.ts` file](https://github.com/octokit/plugin-rest-endpoint-methods.js/blob/master/src/generated/endpoints.ts) defines the **② endpoint default options** `method`, `url`, and in some cases `mediaType` and `headers`.

**② endpoint default options** are merged with **① global defaults**, which are based on [@octokit/endpoint/src/defaults.ts](https://github.com/octokit/endpoint.js/blob/master/src/defaults.ts) and the options that were passed into the `new Octokit(options)` constructor.

Expand All @@ -24,7 +24,7 @@ Both are merged with **③ user options** passed into each method. Altogether th
**Example**: get all public repositories of the the [@octokit](https://github.com/octokit) GitHub organization.

```js
octokit.repos.listForOrg({ org: "octokit", type: "public" });
octokit.rest.repos.listForOrg({ org: "octokit", type: "public" });
```

**④ endpoint options** will be
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const { Octokit } = require("@octokit/rest");
const octokit = new Octokit();

// Compare: https://docs.github.com/en/rest/reference/repos/#list-organization-repositories
octokit.repos
octokit.rest.repos
.listForOrg({
org: "octokit",
type: "public",
Expand All @@ -50,7 +50,7 @@ octokit.repos
});
```

See https://octokit.github.io/rest.js/ for full documentation.
See https://octokit.rest.github.io/rest.js/ for full documentation.

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Documentation

Static documentation website, built with [Gatsby](https://www.gatsbyjs.org/) using [`@octokit/rest`](https://github.com/octokit/rest.js/) and deployed to GitHub Pages: [https://octokit.github.io/rest.js/](https://octokit.github.io/rest.js/)
Static documentation website, built with [Gatsby](https://www.gatsbyjs.org/) using [`@octokit/rest`](https://github.com/octokit/rest.js/) and deployed to GitHub Pages: [https://octokit.rest.github.io/rest.js/](https://octokit.rest.github.io/rest.js/)

## Local Development

Expand Down
8 changes: 4 additions & 4 deletions docs/src/pages/api/00_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ Most of GitHub’s REST API endpoints have matching methods. All endpoint method
(async () => {
```
For example to retrieve a pull request, use [`octokit.pulls.get()`](#octokit-routes-pulls-get). We recommend to use the search above to find the endpoint method you are looking for
For example to retrieve a pull request, use [`octokit.rest.pulls.get()`](#octokit-routes-pulls-get). We recommend to use the search above to find the endpoint method you are looking for
```js
const { data: pullRequest } = await octokit.pulls.get({
const { data: pullRequest } = await octokit.rest.pulls.get({
owner: "octokit",
repo: "rest.js",
pull_number: 123,
Expand All @@ -122,7 +122,7 @@ Some API endpoints support alternative response formats, see [Media types](https
Learn more about [request formats](#request-formats-aborts).
```js
const { data: diff } = await octokit.pulls.get({
const { data: diff } = await octokit.rest.pulls.get({
owner: "octokit",
repo: "rest.js",
pull_number: 123,
Expand Down Expand Up @@ -160,7 +160,7 @@ Some endpoints return a list which has to be paginated in order to retrieve the
Learn more about [pagination](#pagination).
```js
octokit.paginate(octokit.issues.listForRepo, {
octokit.paginate(octokit.rest.issues.listForRepo, {
owner: 'octokit',
repo: 'rest.js'
})
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/api/02_previews.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Previews can also be enabled for a single request by passing the `mediaType.prev
```js
const {
data: { topics },
} = await octokit.repos.get({
} = await octokit.rest.repos.get({
owner: "octokit",
repo: "rest.js",
mediaType: {
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/api/03_request_formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Some API endpoints support alternative response formats, see [Media types](https
For example, to request a [pull request as diff format](https://docs.github.com/en/rest/overview/media-types#commits-commit-comparison-and-pull-requests), set the `mediaType.format` option

```js
const { data: prDiff } = await octokit.pulls.get({
const { data: prDiff } = await octokit.rest.pulls.get({
owner: "octokit",
repo: "rest.js",
pull_number: 1278,
Expand All @@ -21,7 +21,7 @@ The [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortCont

```js
const controller = new AbortController();
const { data: prDiff } = await octokit.pulls.get({
const { data: prDiff } = await octokit.rest.pulls.get({
owner: "octokit",
repo: "rest.js",
pull_number: 1278,
Expand Down
6 changes: 3 additions & 3 deletions docs/src/pages/api/04_custom_requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ octokit.request("GET /");

The `baseUrl`, headers and other defaults are already set. For more information on the `octokit.request()` API see [`octokit/request.js`](https://github.com/octokit/request.js/)

All the endpoint methods such as `octokit.repos.get()` are aliases of `octokit.request()` with pre-bound default options. So you can use the `@octokit/request` API to get the default options or get generic request option to use with your preferred request library.
All the endpoint methods such as `octokit.rest.repos.get()` are aliases of `octokit.request()` with pre-bound default options. So you can use the `@octokit/request` API to get the default options or get generic request option to use with your preferred request library.

```js
const defaultOptions = octokit.repos.get.endpoint.DEFAULTS;
const requestOptions = octokit.repos.get.endpoint({
const defaultOptions = octokit.rest.repos.get.endpoint.DEFAULTS;
const requestOptions = octokit.rest.repos.get.endpoint({
owner: "octokit",
repo: "rest.js",
});
Expand Down
8 changes: 4 additions & 4 deletions docs/src/pages/api/05_pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ octokit
})
.then((issues) => {
// issues is an array of all issue objects. It is not wrapped in a { data, headers, status, url } object
// like results from `octokit.request()` or any of the endpoint methods such as `octokit.issues.listForRepo()`
// like results from `octokit.request()` or any of the endpoint methods such as `octokit.rest.issues.listForRepo()`
});
```

Expand Down Expand Up @@ -45,11 +45,11 @@ octokit.paginate("GET /organizations", (response, done) => {
});
```

To paginate responses for one of the registered endpoint methods such as `octokit.issues.listForRepo()` you can pass the method directly as first argument to `octokit.paginate`:
To paginate responses for one of the registered endpoint methods such as `octokit.rest.issues.listForRepo()` you can pass the method directly as first argument to `octokit.paginate`:

```js
octokit
.paginate(octokit.issues.listForRepo, {
.paginate(octokit.rest.issues.listForRepo, {
owner: "octokit",
repo: "rest.js",
})
Expand All @@ -62,7 +62,7 @@ If your runtime environment supports async iterators (such as most modern browse

```js
for await (const response of octokit.paginate.iterator(
octokit.issues.listForRepo,
octokit.rest.issues.listForRepo,
{
owner: "octokit",
repo: "rest.js",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/api/07_custom_endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function myPlugin(octokit, options) {

---

You can register custom endpoint methods such as `octokit.repos.get()` using the `octokit.registerEndpoints(routes)` method
You can register custom endpoint methods such as `octokit.rest.repos.get()` using the `octokit.registerEndpoints(routes)` method

```js
octokit.registerEndpoints({
Expand Down
Loading

0 comments on commit 40ee966

Please sign in to comment.