GitHub API中blob_url,raw_url和contents_url有什么区别?

时间:2016-02-12 05:26:08

标签: json git api rest github

GitHub API documentation显示了以下API调用答案示例。

  "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"
    }
  ]

现在我想要使用答案中单个文件的内容  我应该从

中选择哪三个链接
  • blub_url
  • raw_url
  • contents_url

有什么区别?什么是出于什么目的?

1 个答案:

答案 0 :(得分:2)

content_url一个(来自repo get content API)支持custom media type

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

raw_url是第一种媒体类型的快捷方式。

blob_url仅查看files in commits,并将该文件的内容提供为git仓库中的库存内容,而不包含媒体类型的概念。