简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM