Git ๋ฏธํ์ธ ๊ฐ์ฒด์ ๋ํ REST API ์๋ํฌ์ธํธ
๊ฐ ํ์ผ์ ์ฝํ ์ธ ๋ฅผ ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ ์ฅํ๋ ๋ฐ ์ฌ์ฉ๋๋ ๊ฐ์ฒด ํ์์ธ Git BLOB(Binary Large Object)์ ์ํธ ์์ฉํ๋ ค๋ฉด REST API๋ฅผ ์ฌ์ฉํ์ญ์์ค.
Git Blob ์ ๋ณด
Git BLOB(Binary Large Object)์ ๊ฐ ํ์ผ์ ์ฝํ ์ธ ๋ฅผ ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ ์ฅํ๋ ๋ฐ ์ฌ์ฉ๋๋ ๊ฐ์ฒด ํ์์ ๋๋ค. ํ์ผ์ SHA-1 ํด์๋ ๊ณ์ฐ๋์ด BLOB ๊ฐ์ฒด์ ์ ์ฅ๋ฉ๋๋ค. ์๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ๋ฉด GitHub์์ Git ๋ฐ์ดํฐ๋ฒ ์ด์ค์ BLOB ๊ฐ์ฒด๋ฅผ ์ฝ๊ณ ์ธ ์ ์์ต๋๋ค. BLOB์ ์ฌ์ฉ์ ์ง์ ๋ฏธ๋์ด ์ ํ์ ํ์ฉํฉ๋๋ค. API์์ ๋ฏธ๋์ด ํ์์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์์ธํ ์ ๋ณด๋ REST API ์์์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
Create a blob
"Create a blob"์ ๋ํ ์ธ๋ถํ๋ ์ก์ธ์ค ํ ํฐ
์ด ์๋ํฌ์ธํธ๋ ๋ค์ ์ธ๋ถํ๋ ํ ํฐ ํ์์์ ์๋ํฉ๋๋ค.:
- GitHub ์ฑ ์ฌ์ฉ์ ์ก์ธ์ค ํ ํฐ
- GitHub ์ฑ ์ค์น ์ก์ธ์ค ํ ํฐ
- ์ธ๋ถํ๋ ๊ฐ์ธ์ฉ ์ก์ธ์ค ํ ํฐ
์ธ๋ถํ๋ ํ ํฐ์๋ ๋ค์ ๊ถํ ์งํฉ์ด ์์ด์ผ ํฉ๋๋ค.:
- "Contents" repository permissions (write)
"Create a blob"์ ๋ํ ๋งค๊ฐ ๋ณ์
์์ฑ, ํ์, ์ค๋ช |
---|
accept string Setting to |
์์ฑ, ํ์, ์ค๋ช |
---|
owner string RequiredThe account owner of the repository. The name is not case sensitive. |
repo string RequiredThe name of the repository without the |
์์ฑ, ํ์, ์ค๋ช |
---|
content string RequiredThe new blob's content. |
encoding string The encoding used for ๊ธฐ๋ณธ๊ฐ: |
"Create a blob"์ ๋ํ HTTP ์๋ต ์ํ ์ฝ๋
์ํ ์ฝ๋ | ์ค๋ช |
---|---|
201 | Created |
403 | Forbidden |
404 | Resource not found |
409 | Conflict |
422 | Validation failed |
"Create a blob"์ ๋ํ ์ฝ๋ ์ํ
์์ฒญ ์์
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/git/blobs \
-d '{"content":"Content of the blob","encoding":"utf-8"}'
Response
Status: 201
{
"url": "https://api.github.com/repos/octocat/example/git/blobs/3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15",
"sha": "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15"
}
Get a blob
The content
in the response will always be Base64 encoded.
This endpoint supports the following custom media types. For more information, see "Media types."
application/vnd.github.raw+json
: Returns the raw blob data.application/vnd.github+json
: Returns a JSON representation of the blob withcontent
as a base64 encoded string. This is the default if no media type is specified.
Note This endpoint supports blobs up to 100 megabytes in size.
"Get a blob"์ ๋ํ ์ธ๋ถํ๋ ์ก์ธ์ค ํ ํฐ
์ด ์๋ํฌ์ธํธ๋ ๋ค์ ์ธ๋ถํ๋ ํ ํฐ ํ์์์ ์๋ํฉ๋๋ค.:
- GitHub ์ฑ ์ฌ์ฉ์ ์ก์ธ์ค ํ ํฐ
- GitHub ์ฑ ์ค์น ์ก์ธ์ค ํ ํฐ
- ์ธ๋ถํ๋ ๊ฐ์ธ์ฉ ์ก์ธ์ค ํ ํฐ
์ธ๋ถํ๋ ํ ํฐ์๋ ๋ค์ ๊ถํ ์งํฉ์ด ์์ด์ผ ํฉ๋๋ค.:
- "Contents" repository permissions (read)
๊ณต์ฉ ๋ฆฌ์์ค๋ง ์์ฒญ๋๋ ๊ฒฝ์ฐ ์ธ์ฆ ๋๋ ์์ ์ธ๊ธํ ๊ถํ ์์ด ์ด ์๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
"Get a blob"์ ๋ํ ๋งค๊ฐ ๋ณ์
์์ฑ, ํ์, ์ค๋ช |
---|
accept string Setting to |
์์ฑ, ํ์, ์ค๋ช |
---|
owner string RequiredThe account owner of the repository. The name is not case sensitive. |
repo string RequiredThe name of the repository without the |
file_sha string Required |
"Get a blob"์ ๋ํ HTTP ์๋ต ์ํ ์ฝ๋
์ํ ์ฝ๋ | ์ค๋ช |
---|---|
200 | OK |
403 | Forbidden |
404 | Resource not found |
409 | Conflict |
422 | Validation failed, or the endpoint has been spammed. |
"Get a blob"์ ๋ํ ์ฝ๋ ์ํ
์์ฒญ ์์
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/git/blobs/FILE_SHA
Response
Status: 200
{
"content": "Q29udGVudCBvZiB0aGUgYmxvYg==",
"encoding": "base64",
"url": "https://api.github.com/repos/octocat/example/git/blobs/3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15",
"sha": "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15",
"size": 19,
"node_id": "Q29udGVudCBvZiB0aGUgYmxvYg=="
}