Skip to content

Commit 4539527

Browse files
authored
📝 add call rest api directly docs
1 parent 1857d5e commit 4539527

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

docs/usage/rest-api.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,61 @@ You can also provide a custom map function to handle complex pagination (such as
319319
accessible_repo: Repository
320320
print(accessible_repo.full_name)
321321
```
322+
323+
## Calling API Directly
324+
325+
In some cases, you may want to call the API directly without using the generated methods. You can use the `github.request` / `github.arequest` method to make a raw request.
326+
327+
For example, to upload a release asset:
328+
329+
=== "Sync"
330+
331+
```python hl_lines="11-18"
332+
from githubkit import GitHub
333+
from githubkit.versions.latest.models import Release, ReleaseAsset
334+
335+
github = GitHub()
336+
337+
resp = github.rest.repos.get_release_by_tag(
338+
"owner", "repo", "tag_name"
339+
)
340+
release: Release = resp.parsed_data
341+
342+
resp = github.request(
343+
"POST",
344+
release.upload_url.split("{?")[0], # (1)!
345+
params={"name": "test", "label": "description"},
346+
content=b"file content",
347+
headers={"Content-Type": "application/zip"},
348+
response_model=ReleaseAsset,
349+
)
350+
asset: ReleaseAsset = resp.parsed_data
351+
```
352+
353+
1. The release `upload_url` is a template URL. In this example, we simply remove the template part.
354+
355+
=== "Async"
356+
357+
```python hl_lines="11-18"
358+
from githubkit import GitHub
359+
from githubkit.versions.latest.models import Release, ReleaseAsset
360+
361+
github = GitHub()
362+
363+
resp = await github.rest.repos.async_get_release_by_tag(
364+
"owner", "repo", "tag_name"
365+
)
366+
release: Release = resp.parsed_data
367+
368+
resp = await github.arequest(
369+
"POST",
370+
release.upload_url.split("{?")[0], # (1)!
371+
params={"name": "test", "label": "description"},
372+
content=b"file content",
373+
headers={"Content-Type": "application/zip"},
374+
response_model=ReleaseAsset,
375+
)
376+
asset: ReleaseAsset = resp.parsed_data
377+
```
378+
379+
1. The release `upload_url` is a template URL. In this example, we simply remove the template part.

0 commit comments

Comments
 (0)