API Documentation
Overview
Our API allows you to download GitHub repositories as ZIP files programmatically. This is useful for automation, CI/CD pipelines, or any scenario where you need to fetch repository content without using Git commands.
Endpoint
GET /api/zipParameters
| Parameter | Required | Description |
|---|---|---|
| url | Yes | The GitHub repository URL (e.g., https://github.com/owner/repo) |
| commit | No | The commit SHA to download. If not provided, the latest commit from the default branch will be used. |
| token | No | GitHub personal access token with repo scope. Required for private repositories. |
Response
The API returns a ZIP file as an attachment with the repository contents.
Headers:
Content-Type: application/zipContent-Disposition: attachment; filename="repo-commit.zip"Examples
Basic Usage
Download the latest commit from a public repository:
https://git-downloader.com/api/zip?url=https://github.com/facebook/reactSpecific Commit
Download a specific commit:
https://git-downloader.com/api/zip?url=https://github.com/facebook/react&commit=0cf22a4cd5b5b947d06a63867419c3f26a967984Private Repository
Download from a private repository using a token:
https://git-downloader.com/api/zip?url=https://github.com/owner/private-repo&token=ghp_your_personal_access_tokenError Responses
| Status Code | Description |
|---|---|
| 400 | Missing or invalid parameters |
| 401 | Authentication failed (invalid token) |
| 403 | Rate limit exceeded or insufficient permissions |
| 404 | Repository or commit not found |
| 500 | Internal server error |
Code Examples
JavaScript (Fetch)
// Download and save a repository as a zip file
async function downloadRepo() {
const url = 'https://git-downloader.com/api/zip?url=https://github.com/owner/repo';
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Error: ${response.status} ${response.statusText}`);
}
// Get the filename from the Content-Disposition header
const contentDisposition = response.headers.get('content-disposition');
const filename = contentDisposition
? contentDisposition.split('filename=')[1].replace(/"/g, '')
: 'repository.zip';
// Convert the response to a blob
const blob = await response.blob();
// Create a download link and trigger the download
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(downloadUrl);
} catch (error) {
console.error('Download failed:', error);
}
}Python
import requests
import os
def download_repository(github_url, commit=None, token=None):
"""
Download a GitHub repository as a zip file
Args:
github_url (str): GitHub repository URL
commit (str, optional): Commit SHA
token (str, optional): GitHub personal access token
"""
# Construct the API URL
api_url = 'https://git-downloader.com/api/zip'
params = {'url': github_url}
if commit:
params['commit'] = commit
if token:
params['token'] = token
try:
# Make the request
response = requests.get(api_url, params=params, stream=True)
response.raise_for_status()
# Get filename from Content-Disposition header
content_disposition = response.headers.get('content-disposition', '')
if 'filename=' in content_disposition:
filename = content_disposition.split('filename=')[1].strip('"')
else:
# Extract repo name from GitHub URL
repo_name = github_url.rstrip('/').split('/')[-1]
filename = f"{repo_name}.zip"
# Save the file
with open(filename, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f"Repository downloaded successfully as {filename}")
return filename
except requests.exceptions.RequestException as e:
print(f"Error downloading repository: {e}")
return None
# Example usage
download_repository('https://github.com/owner/repo')