How is codeload.github.com different to api.github.com?

雨燕双飞 提交于 2020-05-12 04:38:07

问题


I was browsing the next.js repository and noticed this function that downloads and extracts a template from GitHub, with tar:

export async function downloadAndExtractExample(
  root: string,
  name: string
): Promise<void> {
  return await promisePipe(
    got.stream('https://codeload.github.com/zeit/next.js/tar.gz/canary'),
    tar.extract({ cwd: root, strip: 3 }, [`next.js-canary/examples/${name}`])
  )
}

I searched on StackOverflow and I only found this:

  • GitHub Api download zip or tarball link

That's a thread explaining how you can pull a tar.gz from GitHub, but there is no mention of the "codeload" subdomain. How is it different to "api"?


回答1:


The GitHub API provides the best way to get a URL to download an archive. When you make a GET request on that URL, it will redirect you to a URL on codeload.github.com. codeload is the service which provides archives for download and it's on its own domain for caching reasons.

While it's possible to use the codeload URL directly, you generally want to use the API URL, since it handles things like authentication more gracefully, and the codeload URLs for private repositories are generally ephemeral.



来源:https://stackoverflow.com/questions/60188254/how-is-codeload-github-com-different-to-api-github-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!