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:
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"?
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.
Learn about GitHub's APIs to extend and customize your GitHub experience. There are two stable versions of the GitHub API: the REST API and the GraphQL API.
The Users API allows to get public and private information about the authenticated user. Users. Get the authenticated user. Update the authenticated user. List users.
The GitHub developer's site: https://developer.github.com/v3/, shows this URL: https://api.github.com.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With