Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between blob_url, raw_url and contents_url in GitHub API?

The GitHub API documentation shows the following example of an answer of an API call.

  "files": [
    {
      "sha": "bbcd538c8e72b8c175046e27cc8f907076331401",
      "filename": "file1.txt",
      "status": "added",
      "additions": 103,
      "deletions": 21,
      "changes": 124,
      "blob_url": "https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
      "raw_url": "https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
      "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e",
      "patch": "@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"
    }
  ]

Now I want to consume the content of the single files of the answer.
Which of the 3 links should I choose from

  • blub_url
  • raw_url
  • contents_url

What are the differences? What is meant for what purpose?

like image 294
Ernst Robert Avatar asked Oct 18 '22 15:10

Ernst Robert


1 Answers

The content_url one (from repo get content API) supports custom media type

application/vnd.github.VERSION.raw
application/vnd.github.VERSION.html

The raw_url one is a shortcut to the first of those media types.

The blob_url one is only see for files in commits, and serves the content of that file as stocked in a git repo, without notion of media type.

like image 60
VonC Avatar answered Oct 23 '22 13:10

VonC