Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ the passed options and sends the request using [fetch](https://developer.mozilla
🤩 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

```js
request("POST /repos/:owner/:repo/issues/:number/labels", {
request("POST /repos/{owner}/{repo}/issues/{number}/labels", {
mediaType: {
previews: ["symmetra"],
},
Expand Down Expand Up @@ -99,7 +99,7 @@ const { request } = require("@octokit/request");
```js
// Following GitHub docs formatting:
// https://developer.github.com/v3/repos/#list-organization-repositories
const result = await request("GET /orgs/:org/repos", {
const result = await request("GET /orgs/{org}/repos", {
headers: {
authorization: "token 0000000000000000000000000000000000000001",
},
Expand Down Expand Up @@ -139,7 +139,7 @@ Alternatively, pass in a method and a url
```js
const result = await request({
method: "GET",
url: "/orgs/:org/repos",
url: "/orgs/{org}/repos",
headers: {
authorization: "token 0000000000000000000000000000000000000001",
},
Expand Down Expand Up @@ -180,11 +180,14 @@ const requestWithAuth = request.defaults({
});

const { data: app } = await requestWithAuth("GET /app");
const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
owner: "octocat",
repo: "hello-world",
title: "Hello from the engine room",
});
const { data: app } = await requestWithAuth(
"POST /repos/{owner}/{repo}/issues",
{
owner: "octocat",
repo: "hello-world",
title: "Hello from the engine room",
}
);
```

## request()
Expand Down Expand Up @@ -215,7 +218,7 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
String
</td>
<td>
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>
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>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -283,7 +286,7 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
</td>
<td>
<strong>Required.</strong> A path or full URL which may contain <code>:variable</code> or <code>{variable}</code> placeholders,
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>.
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>.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -356,7 +359,7 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {

All other options except `options.request.*` will be passed depending on the `method` and `url` options.

1. 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`
1. 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`
2. If the `method` is `GET` or `HEAD`, the option is passed as query parameter
3. Otherwise the parameter is passed in the request body as JSON key.

Expand Down Expand Up @@ -421,7 +424,7 @@ const myrequest = require("@octokit/request").defaults({
per_page: 100,
});

myrequest(`GET /orgs/:org/repos`);
myrequest(`GET /orgs/{org}/repos`);
```

You can call `.defaults()` again on the returned method, the defaults will cascade.
Expand Down Expand Up @@ -450,7 +453,7 @@ by the global default.
See https://github.com/octokit/endpoint.js. Example

```js
const options = request.endpoint("GET /orgs/:org/repos", {
const options = request.endpoint("GET /orgs/{org}/repos", {
org: "my-project",
type: "private",
});
Expand Down
Loading