Skip to main content
์ด์ œ REST API์˜ ๋ฒ„์ „์ด ์ง€์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ "API ๋ฒ„์ „ ๊ด€๋ฆฌ ์ •๋ณด"๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

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"์— ๋Œ€ํ•œ ์„ธ๋ถ„ํ™”๋œ ์•ก์„ธ์Šค ํ† ํฐ

์ด ์—”๋“œํฌ์ธํŠธ๋Š” ๋‹ค์Œ ์„ธ๋ถ„ํ™”๋œ ํ† ํฐ ํ˜•์‹์—์„œ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.:

์„ธ๋ถ„ํ™”๋œ ํ† ํฐ์—๋Š” ๋‹ค์Œ ๊ถŒํ•œ ์ง‘ํ•ฉ์ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.:

  • "Contents" repository permissions (write)

"Create a blob"์— ๋Œ€ํ•œ ๋งค๊ฐœ ๋ณ€์ˆ˜

๋จธ๋ฆฌ๊ธ€
์†์„ฑ, ํ˜•์‹, ์„ค๋ช…
accept string

Setting to application/vnd.github+json is recommended.

๊ฒฝ๋กœ ๋งค๊ฐœ ๋ณ€์ˆ˜
์†์„ฑ, ํ˜•์‹, ์„ค๋ช…
owner string Required

The account owner of the repository. The name is not case sensitive.

repo string Required

The name of the repository without the .git extension. The name is not case sensitive.

๋ณธ๋ฌธ ๋งค๊ฐœ ๋ณ€์ˆ˜
์†์„ฑ, ํ˜•์‹, ์„ค๋ช…
content string Required

The new blob's content.

encoding string

The encoding used for content. Currently, "utf-8" and "base64" are supported.

๊ธฐ๋ณธ๊ฐ’: utf-8

"Create a blob"์— ๋Œ€ํ•œ HTTP ์‘๋‹ต ์ƒํƒœ ์ฝ”๋“œ

์ƒํƒœ ์ฝ”๋“œ์„ค๋ช…
201

Created

403

Forbidden

404

Resource not found

409

Conflict

422

Validation failed

"Create a blob"์— ๋Œ€ํ•œ ์ฝ”๋“œ ์ƒ˜ํ”Œ

์š”์ฒญ ์˜ˆ์ œ

post/repos/{owner}/{repo}/git/blobs
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 with content 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"์— ๋Œ€ํ•œ ์„ธ๋ถ„ํ™”๋œ ์•ก์„ธ์Šค ํ† ํฐ

์ด ์—”๋“œํฌ์ธํŠธ๋Š” ๋‹ค์Œ ์„ธ๋ถ„ํ™”๋œ ํ† ํฐ ํ˜•์‹์—์„œ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.:

์„ธ๋ถ„ํ™”๋œ ํ† ํฐ์—๋Š” ๋‹ค์Œ ๊ถŒํ•œ ์ง‘ํ•ฉ์ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.:

  • "Contents" repository permissions (read)

๊ณต์šฉ ๋ฆฌ์†Œ์Šค๋งŒ ์š”์ฒญ๋˜๋Š” ๊ฒฝ์šฐ ์ธ์ฆ ๋˜๋Š” ์•ž์„œ ์–ธ๊ธ‰ํ•œ ๊ถŒํ•œ ์—†์ด ์ด ์—”๋“œํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

"Get a blob"์— ๋Œ€ํ•œ ๋งค๊ฐœ ๋ณ€์ˆ˜

๋จธ๋ฆฌ๊ธ€
์†์„ฑ, ํ˜•์‹, ์„ค๋ช…
accept string

Setting to application/vnd.github+json is recommended.

๊ฒฝ๋กœ ๋งค๊ฐœ ๋ณ€์ˆ˜
์†์„ฑ, ํ˜•์‹, ์„ค๋ช…
owner string Required

The account owner of the repository. The name is not case sensitive.

repo string Required

The name of the repository without the .git extension. The name is not case sensitive.

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"์— ๋Œ€ํ•œ ์ฝ”๋“œ ์ƒ˜ํ”Œ

์š”์ฒญ ์˜ˆ์ œ

get/repos/{owner}/{repo}/git/blobs/{file_sha}
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==" }