UNPKG

2.05 kBMarkdownView Raw
1[back to `@octokit/rest`]('../..')
2
3# `@octokit/rest/endpoint`
4
5> Turn REST API endpoint options into generic request options
6
7---
8
9# ⚠️ This is not a public API at this point and can change at any time
10
11---
12
13## Usage
14
15```js
16const octokitRestEndpoint = require('@octokit/rest/lib/endpoint')
17
18const options = octokitRestEndpoint({
19 // request options
20 method: 'GET',
21 url: '/orgs/:org/repos',
22 // parameters
23 org: 'octokit',
24 type: 'private'
25})
26```
27
28`options` would now look something like
29
30```js
31{
32 method: 'GET',
33 url: 'https://api.github.com/orgs/octokit/repos?type=private',
34 headers: {
35 'user-agent': 'myApp v1.2.3',
36 accept: 'application/vnd.github.v3+json'
37 }
38}
39```
40
41You can pass them to your request library of preference.
42
43## Options
44
45### `method`
46
47Any supported [http verb](https://developer.github.com/v3/#http-verbs), case insensitive.
48
49### `url`
50
51A path or full URL which may contain `:variable` or `{variable}` placeholders,
52e.g. `/orgs/:org/repos`. The `url` is parsed using
53
54## Defaults
55
56| Name | Value |
57|------------------------|-------------------------------------------------------------------------------------|
58| **method** | `'get'` |
59| **baseUrl** | `'https://api.github.com'` |
60| **headers.accept** | `'application/vnd.github.v3+json'` |
61| **headers.user-agent** | `'octokit/rest.js v1.2.3'` (1.2.3 being the current `@octokit/rest` version number) plus what ever [universal-user-agent](https://www.npmjs.com/package/universal-user-agent) returns. If you pass a custom value such as `myApp v1.2.3` then it will be used as prefix |
62
63_To be done_: change defaults with
64
65```js
66const octokitRestEndpoint = require('@octokit/rest/lib/endpoint').defaults({
67 baseUrl: 'http://my-custom-host/api/v3'
68})
69```