`@octokit/endpoint` combines [GitHub REST API routes](https://developer.github.com/v3/) with your parameters and turns them into generic request options that can be used in any request library.
<!-- update table of contents by running `npx markdown-toc README.md -i` -->
<!-- toc -->
- [Usage](#usage)
- [API](#api)
- [`endpoint(route, options)` or `endpoint(options)`](#endpointroute-options-or-endpointoptions)
- [`endpoint.defaults()`](#endpointdefaults)
- [`endpoint.DEFAULTS`](#endpointdefaults)
- [`endpoint.merge(route, options)` or `endpoint.merge(options)`](#endpointmergeroute-options-or-endpointmergeoptions)
- [`endpoint.parse()`](#endpointparse)
- [Special cases](#special-cases)
- [The `data` parameter – set request body directly](#the-data-parameter-%E2%80%93-set-request-body-directly)
- [Set parameters for both the URL/query and the request body](#set-parameters-for-both-the-urlquery-and-the-request-body)
If set, it has to be a string consisting of URL and the request method, e.g., <code>GET /orgs/{org}</code>. If it’s set to a URL, only the method defaults to <code>GET</code>.
<strong>Required unless <code>route</code> is set.</strong> Any supported <ahref="https://developer.github.com/v3/#http-verbs">http verb</a>. <em>Defaults to <code>GET</code></em>.
</td>
</tr>
<tr>
<th>
<code>options.url</code>
</th>
<td>
String
</td>
<td>
<strong>Required unless <code>route</code> is set.</strong> A path or full URL which may contain <code>:variable</code> or <code>{variable}</code> placeholders,
<em>Defaults to <code>https://api.github.com</code></em>.
</td>
</tr>
<tr>
<th>
<code>options.headers</code>
</th>
<td>
Object
</td>
<td>
Custom headers. Passed headers are merged with defaults:<br>
<em><code>headers['user-agent']</code> defaults to <code>octokit-endpoint.js/1.2.3</code> (where <code>1.2.3</code> is the released version)</em>.<br>
<em><code>headers['accept']</code> defaults to <code>application/vnd.github.v3+json</code></em>.<br>
</td>
</tr>
<tr>
<th>
<code>options.mediaType.format</code>
</th>
<td>
String
</td>
<td>
Media type param, such as <code>raw</code>, <code>diff</code>, or <code>text+json</code>. See <ahref="https://developer.github.com/v3/media/">Media Types</a>. Setting <code>options.mediaType.format</code> will amend the <code>headers.accept</code> value.
</td>
</tr>
<tr>
<th>
<code>options.data</code>
</th>
<td>
Any
</td>
<td>
Set request body directly instead of setting it to JSON based on additional parameters. See <ahref="#data-parameter">"The <code>data</code> parameter"</a> below.
</td>
</tr>
<tr>
<th>
<code>options.request</code>
</th>
<td>
Object
</td>
<td>
Pass custom meta information for the request. The <code>request</code> object will be returned as is.
</td>
</tr>
</tbody>
</table>
All other options will be passed depending on the `method` and `url` options.
1. If the option key has a placeholder in the `url`, it will be used as the 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`.
Stateless method to turn endpoint options into request options. Calling
`endpoint(options)` is the same as calling `endpoint.parse(endpoint.merge(options))`.
## Special cases
<aname="data-parameter"></a>
### The `data` parameter – set request body directly
Some 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.
```js
const options = endpoint("POST /markdown/raw", {
data: "Hello world github/linguist#1 **cool**, and #1!",
headers: {
accept: "text/html;charset=utf-8",
"content-type": "text/plain",
},
});
// options is
// {
// method: 'post',
// url: 'https://api.github.com/markdown/raw',
// headers: {
// accept: 'text/html;charset=utf-8',
// 'content-type': 'text/plain',
// 'user-agent': userAgent
// },
// body: 'Hello world github/linguist#1 **cool**, and #1!'
// }
```
### Set parameters for both the URL/query and the request body
There 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).