获取 GitHub 上 JSON 数据的三种方式

1,952次阅读
没有评论

JSON 是 Web 中数据表示和传输最通用的格式,GitHub 是程序员所热爱的极乐开源社区,有时候我们在仓库存放一些 .json 文件,或者通过 GitHub Actions 自动构建输出一些 .json 文件,作为一个轻量数据源,那么我们如何去获取呢?

const REPO = 'reuixiy/io-oi.me'
const BRANCH = 'build'
const FILE_PATH = 'foo/bar.json'
// 1. raw.githubusercontent.com

`https://raw.githubusercontent.com/${REPO}/${BRANCH}/${FILE_PATH}`

这种方式最简单,但是由于该域名在国内访问不畅,有时可能会带来麻烦,可以尝试以下两种方案。

// 2. api.github.com

`https://api.github.com/repos/${REPO}/contents/${FILE_PATH}?ref=${BRANCH}`

async function getFooBar() {
const res = await fetch(URL, {
// Required headers
headers: {
// See https://docs.github.com/en/rest/overview/media-types
Accept: 'application/vnd.github.v3.raw',
// See https://docs.github.com/en/rest/guides/getting-started-with-the-rest-api#authentication
// Authorization: 'token ${GITHUB_TOKEN}',
},
})
const fooBar = await res.json()

return fooBar
}

这个域名目前在国内访问通畅,但是需要额外的 headers,且未验证的客户端每小时有 60 次请求限制。

// 3. github.io

`https://<username>.github.io/<repository>/${FILE_PATH}`

这种方式就是将 .json 文件部署到 GitHub Pages,可访问性和速度都不错,参考 https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages

 Read More 

正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)

文心AIGC

2023 年 3 月
 12345
6789101112
13141516171819
20212223242526
2728293031  
文心AIGC
文心AIGC
人工智能ChatGPT,AIGC指利用人工智能技术来生成内容,其中包括文字、语音、代码、图像、视频、机器人动作等等。被认为是继PGC、UGC之后的新型内容创作方式。AIGC作为元宇宙的新方向,近几年迭代速度呈现指数级爆发,谷歌、Meta、百度等平台型巨头持续布局
文章搜索
热门文章
手把手教你用AI 10分钟生成一个APP!零基础也能搞定

手把手教你用AI 10分钟生成一个APP!零基础也能搞定

今日,我将向大家展示DeepSeek的全新玩法——从零开始,利用AI创建一个完整的应用程序。借助DeepSee...
最新评论
ufabet ufabet มีเกมให้เลือกเล่นมากมาย: เกมเดิมพันหลากหลาย ครบทุกค่ายดัง
tornado crypto mixer tornado crypto mixer Discover the power of privacy with TornadoCash! Learn how this decentralized mixer ensures your transactions remain confidential.
ดูบอลสด ดูบอลสด Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
Obrazy Sztuka Nowoczesna Obrazy Sztuka Nowoczesna Thank you for this wonderful contribution to the topic. Your ability to explain complex ideas simply is admirable.
ufabet ufabet Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
ufabet ufabet You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
ufabet ufabet Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
热评文章
手把手教你用AI 10分钟生成一个APP!零基础也能搞定

手把手教你用AI 10分钟生成一个APP!零基础也能搞定

今日,我将向大家展示DeepSeek的全新玩法——从零开始,利用AI创建一个完整的应用程序。借助DeepSee...