Skip to content

Latest commit

 

History

History
99 lines (73 loc) · 3.34 KB

TODO.md

File metadata and controls

99 lines (73 loc) · 3.34 KB

TODO: fetch updated readme from github repo

how to fetch through an api an updated readme inside a public github repository Fetching a README from a public repository doesn't require authentication. Here's how:

  1. Construct the API Request:

Using cURL:

Bash curl https://api.github.com/repos/OWNER/REPO/readme Use code with caution. Learn more Using Python (with the requests library):

Python import requests

response = requests.get("https://api.github.com/repos/OWNER/REPO/readme")

if response.status_code == 200: readme_content = response.json()["content"] # Decode the Base64-encoded content decoded_content = base64.b64decode(readme_content).decode("utf-8") print(decoded_content) else: print("Error fetching README:", response.text) Use code with caution. Learn more Replace placeholders:

OWNER: The repository owner's username. REPO: The repository name. 2. Parse the Response:

If successful (HTTP status code 200), the response will contain the README content in Base64-encoded format. Decode the content using Base64 decoding. Additional Considerations:

Rate Limits: GitHub API has rate limits even for public access. Check response headers for remaining limits. Specific Branch: To fetch from a specific branch, add ?ref=BRANCH_NAME to the URL. Raw Content: For raw content (without markup), append ?raw=true to the URL. Error Handling: Include error handling in your code to handle potential issues gracefully.

how to fetch through an api an updated readme inside a github repository Here's how to fetch an updated README file from a GitHub repository using its API:

  1. Obtain a Personal Access Token:

Go to your GitHub settings -> Developer settings -> Personal access tokens. Click "Generate new token." Give it a descriptive name and select the "repo" scope. Click "Generate token" and carefully copy the token. 2. Construct the API Request:

Using cURL:

Bash curl -H "Authorization: token YOUR_PERSONAL_ACCESS_TOKEN"
-H "Accept: application/vnd.github.v3+json"
https://api.github.com/repos/OWNER/REPO/readme Use code with caution. Learn more Using Python (with the requests library):

Python import requests

headers = { "Authorization": "token YOUR_PERSONAL_ACCESS_TOKEN", "Accept": "application/vnd.github.v3+json" } response = requests.get("https://api.github.com/repos/OWNER/REPO/readme", headers=headers)

if response.status_code == 200: readme_content = response.json()["content"] # Decode the Base64-encoded content decoded_content = base64.b64decode(readme_content).decode("utf-8") print(decoded_content) else: print("Error fetching README:", response.text) Use code with caution. Learn more Replace placeholders:

YOUR_PERSONAL_ACCESS_TOKEN: Your generated token. OWNER: The repository owner's username. REPO: The repository name. 3. Parse the Response:

If successful (HTTP status code 200), the response will contain the README content in Base64-encoded format. Decode the content using Base64 decoding. Additional Considerations:

Rate Limits: GitHub API has rate limits. Check for response headers for remaining limits. Specific Branch: To fetch from a specific branch, add ?ref=BRANCH_NAME to the URL. Raw Content: For raw content (without markup), append ?raw=true to the URL. Error Handling: Include error handling in your code to gracefully handle issues like invalid tokens or non-existent repositories.