Skip to content

Commit 18ed668

Browse files
committed
📝 improve github enterprise docs (#244)
1 parent dbeefb5 commit 18ed668

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
# Connecting to GitHub Enterprise
22

3-
Connecting to the GitHub Enterprise is similar to the public GitHub API, but requires two specific configurations:
3+
Connecting to GitHub Enterprise is similar to using the public GitHub API, but requires two specific configurations. Each is explained below with brief guidance and examples.
44

5-
- To connect to **GitHub Enterprise Server**, you must provide the server's API endpoint in the `base_url` parameter.
6-
- You need to switch the REST API schema version when using client.
5+
## Provide the server API endpoint
76

8-
=== "Sync"
7+
When connecting to a GitHub Enterprise Server (GHES or GHEC), you must set the server's REST API endpoint via the `base_url` parameter when creating the client. Use the full API base URL for your instance (for example `https://example.ghe.com/api/v3/`). githubkit will ensure the trailing slash is present.
8+
9+
This tells the client where to send REST and GraphQL requests rather than the public GitHub endpoints.
10+
11+
```python hl_lines="4 7"
12+
from githubkit import GitHub
13+
from githubkit.versions.latest.models import PublicUser, PrivateUser
14+
15+
github = GitHub("<your_token_here>", base_url="https://example.ghe.com/api/v3/")
16+
```
17+
18+
## Switch the REST API schema version
919

10-
```python hl_lines="4 7"
11-
from githubkit import GitHub
12-
from githubkit.versions.latest.models import PublicUser, PrivateUser
20+
GitHub Enterprise Server may require a different REST API schema/version than the public API. Use the `rest("<schema-version>")` selector on the client to choose the correct REST schema for your server (for example `ghec-2022-11-28`). Picking the right schema ensures endpoint signatures match your server version and provides autocompletion support in your IDE.
1321

14-
github = GitHub("<your_token_here>", base_url="https://example.ghe.com/api/v3/")
22+
The examples below demonstrate how to use both REST API and GraphQL API calls:
1523

16-
# call GitHub rest api
24+
=== "Sync"
25+
26+
```python hl_lines="2"
27+
# Call the GitHub REST API with a specific schema version
1728
resp = github.rest("ghec-2022-11-28").users.get_authenticated()
1829
user: PublicUser | PrivateUser = resp.parsed_data
1930

20-
# call GitHub graphql api
31+
# Call the GitHub GraphQL API
2132
data: dict = github.graphql("{ viewer { login } }")
2233
```
2334

2435
=== "Async"
2536

26-
```python hl_lines="4 7"
27-
from githubkit import GitHub
28-
from githubkit.versions.latest.models import PublicUser, PrivateUser
29-
30-
github = GitHub("<your_token_here>", base_url="https://example.ghe.com/api/v3/")
31-
32-
# call GitHub rest api
37+
```python hl_lines="2"
38+
# Call the GitHub REST API with a specific schema version
3339
resp = await github.rest("ghec-2022-11-28").users.async_get_authenticated()
3440
user: PublicUser | PrivateUser = resp.parsed_data
3541

36-
# call GitHub graphql api
42+
# Call the GitHub GraphQL API
3743
data: dict = await github.async_graphql("{ viewer { login } }")
3844
```
45+
46+
For more information, see [REST API Versioning](../usage/rest-api.md#rest-api-versioning).

0 commit comments

Comments
 (0)