呼叫 GitHub API
探索 production API — 公開資料不用 key
⏱ 預估 ~9 分鐘
01 · 讀一讀
GitHub REST API 是最適合練習的 API 之一:- 免費對公開資料 — 不用 key - 詳細文件在 docs.github.com/en/rest - 真實資料 — 你真的 repo、commit、個人檔 - 標準模式 — 這裡學的東西,大部分 REST API 都通用
Base URL 是 https://api.github.com。所有 endpoint 接在後面。
重點整理
- 公開資料不用 API key(每 IP 每小時最多 60 個請求)
- 驗證過的請求每小時可以 5,000 個
- 建議加 Accept: application/vnd.github.v3+json header
- 回應資料的欄位通常比你會用到的多 — 挑你要的就好
02 · 真機練習
撈你自己的 GitHub profile(或任何公開使用者)。把 torvalds 換成任何 GitHub username。
curl https://api.github.com/users/torvalds
03 · 真機練習
列出那個使用者的公開 repo。
curl https://api.github.com/users/torvalds/repos
04 · 真機練習
加 query parameter 過濾結果 — 拿最近更新的 3 個 repo,按更新時間排序。
curl "https://api.github.com/users/torvalds/repos?sort=updated&per_page=3"
05 · 真機練習
現在用你自己的 GitHub username 試。把下面的 YOUR_USERNAME 換掉。
curl "https://api.github.com/users/YOUR_USERNAME/repos?sort=updated&per_page=5"
06 · 選擇題
GitHub API 的 base URL 是?
- api.github.com
- github.com/api
- rest.github.com
- github.api.com
07 · 填空
從 GitHub API 列出使用者的 repo,用 path /users/USERNAME/_____。
⚠ 完整互動體驗需要 JavaScript。請啟用 JavaScript 後重新整理。
※ 本站為獨立繁中教學專案,非 Anthropic 官方產品。Claude™ 為 Anthropic, PBC 商標。