Host
https://codechina.csdn.net
接口
目前仅用到 code 平台获取仓库文件内容接口:
GET /projects/:id/repository/files/:file_path/raw
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://codechina.csdn.net/api/v4/projects/13083/repository/files/app%2Fmodels%2Fkey%2Erb/raw?ref=master"
Parameters:
-
file_path
(required) - URL encoded full path to new file, such as lib%2Fclass%2Erb. -
ref
(optional) - The name of branch, tag or commit. Default is the HEAD of the project.
接口请求方式
codechina 基于 gitlab 引擎实现,遵循 restful 规范,所有接口请求方式与 gitlab 一致,请求 header 中需包含校验信息 PRIVATE-TOKEN
。
如:
curl --header "PRIVATE-TOKEN: KSWGFaQPt5DSEcwjq-z" "https://codechina.csdn.net/api/v4/projects/codechina%2Fprogrammer%2F10-years-of-mobile-dev/repository/files/detail.json/raw?ref=master"
访问令牌
注意:所有接口请求 header 中都必须包含访问令牌
PRIVATE-TOKEN
业务调用方式:
获取杂志列表
GET /api/v4/projects/codechina%2Fprogrammer%2Fprogramer_magazine_list/repository/files/list.json/raw?ref=master
{
"default_index": [
{
"id": "1",
"title": "《移动开发十年》",
"path": "codechina/programmer/10-years-of-mobile-dev",
"detail": "detail.json",
"chapters": "chapters.json",
"ref": "master",
"list_image": "https://images.gitbook.cn/Fg_-eDnBvuAVxBrBv2vjzMpQ3e3E",
"original_price": "19.9",
"line_price": "19.9",
"sale_price": "9.9",
"short_description": "我们特别组织了数十位开发者,一方面,是十年改变与回顾...",
"author": {
"username": "programer",
"user_title": "国内开发者的权威刊物",
"nickname": "程序员杂志编辑组"
}
}
]
}
default_index
: 默认排序列表(后面可拓展出其他排序,如:hot_index)
id
:刊物唯一ID(由编辑人员自行定义,如:1)
title
:刊物标题
path
:刊物在 code 上的路径(刊物在 code 平台的唯一标识之一,关键字段,可作为项目id使用,使用时必须将 \
转译为 %2F
)
detail
:详情文件(由编辑定义,协议定为:detail.json
,程序需根据实际值使用,不可直接采用 detail.json
)
chapters
:章节文件(协议定为:chapters.json
)
ref
:分支(必要字段,默认为:master
)
list_image
:列表图
original_price
:原价
line_price
:划线价格
sale_price
:售价
short_description
:短描述
author
:作者
-
username
:用户名 -
user_title
:用户 title -
nickname
:昵称
注意:上面 demo 中 codechina%2Fprogrammer%2Fprogramer_magazine_list
由 path
值转译而来,list.json
为协议固定文件名称,master
为 ref
值。
获取杂志详情
GET /api/v4/projects/codechina%2Fprogrammer%2F10-years-of-mobile-dev/repository/files/detail.json/raw?ref=master
{
"id": "1",
"title": "《移动开发十年》",
"sub_title": "程序员 2.0 第一期",
"path": "codechina/programmer/10-years-of-mobile-dev",
"detail_image": "https://images.gitbook.cn/Fg_-eDnBvuAVxBrBv2vjzMpQ3e3E",
"share_image": "https://images.gitbook.cn/Fg_-eDnBvuAVxBrBv2vjzMpQ3e3E",
"main_image": "https://images.gitbook.cn/Fg_-eDnBvuAVxBrBv2vjzMpQ3e3E",
"index_image": "https://images.gitbook.cn/Fg_-eDnBvuAVxBrBv2vjzMpQ3e3E",
"index_video": "https://live.csdn.net/v/embed/34453",
"index_video_description": "Here is a video description.",
"original_price": "19.9",
"line_price": "19.9",
"sale_price": "9.9",
"short_description": "我们特别组织了数十位开发者,一方面,是十年改变与回顾...",
"chapters": "chapters.json",
"description": "<div id=\"content_views\" class=\"htmledit_views\">\n <div align=\"center\">\n <strong><img height=\"240\" alt=\"\" src=\"https://p-blog.csdn.net/images/p_blog_csdn_net/programmer_editor/EntryImages/20080826/fengmian.jpg\" width=\"190\" align=\"center\"></strong>\n</div> \n<div>\n <strong></strong> \n</div> \n<div>\n <strong>本期特别策划</strong>\n ...",
"author": {
"username": "programer",
"user_title": "国内开发者的权威刊物",
"nickname": "程序员杂志编辑组"
}
}
id
:刊物唯一ID(由编辑人员自行定义,如:1)
title
:刊物标题
sub_title
: 副标题
path
:刊物在 code 上的路径(刊物在 code 平台的唯一标识之一,关键字段,可作为项目id使用,使用时必须将 \
转译为 %2F
)
detail
:详情文件(由编辑定义,协议定为:detail.json
,程序需根据实际值使用,不可直接采用 detail.json
)
chapters
:章节文件(协议定为:chapters.json
)
ref
:分支(必要字段,默认为:master
)
detail_image
:详情图
share_image
:分享图
main_image
: 详情页主图
index_image
: 首页主图
index_video
:杂志主视频
index_video_description
: 杂志主视频描述
original_price
:原价
line_price
:划线价格
sale_price
:售价
description
:描述支持 text
和 html
格式
short_description
:短描述 text
格式,可作为分享描述
author
:作者
-
username
:用户名 -
user_title
:用户 title -
nickname
:昵称
注意:上面 demo 中 detail.json
为列表接口中返回的 detail
字段值,需以列表中具体值为准,如 detail
中包含 /
,需转译为 %2F
。
获取杂志章节列表
GET /api/v4/projects/codechina%2Fprogrammer%2F10-years-of-mobile-dev/repository/files/chapters.json/raw?ref=master
{
"sections": [
{
"title":"开篇",
"sub_title":"开篇词,布拉布拉",
"description":"在移动应用上扮演着重要角色,与基于服务端提供的搜索服务不同,移动端受硬件条件限制。",
"index":"1",
"chapters":[
{
"id": "1",
"title": "十年一顾,iOS 与 Android 这样改变了我们",
"sub_title": "文/胡凯",
"index": "1",
"free_rate": "100",
"description": "基于本地数据的全文搜索(Full-Text-Search,简称 FTS)在移动应用上扮演着重要角色,与基于服务端提供的搜索服务不同,移动端受硬件条件限制,尤其在数据量相对较大的情况下,搜索性能问题表现得十分突出。本文以移动平台广泛采用的 SQLite FTS Extension 为例,介绍了移动平台 FTS 的基本原理,并结合微信 Android 客户端自身实践,重点讲述微信在 FTS 上的一些性能优化经验。",
"chapter_page_url": "https://codechina.gitcode.host/programmer/heti-test/1-10-years-ios-and-android.html",
"chapter_limited_page_url": "https://codechina.gitcode.host/programmer/heti-test/1-10-years-ios-and-android.html"
}
]
},
{
"title":"正文部分",
"sub_title":"正文部分描述,布拉布拉",
"description":"伴随着业务场景需求的变化,58同城 App 在网络架构层面经历了从使用第三方开源网络框架到自主研发框架的不同阶段的不断改进。",
"index":"1",
"chapters":[
{
"id": "2",
"title": "58同城 iOS 客户端网络框架的演进之路",
"sub_title": "文/郭方清",
"index": "2",
"free_rate": "100",
"description": "伴随着业务场景需求的变化,58同城 App 在网络架构层面经历了从使用第三方开源网络框架到自主研发框架的不同阶段的不断改进。本文作者即从 iOS 开发角度具体分享了58同城移动客户端在网络框架层面的几次演变改进实践与经验总结。",
"chapter_page_url": "https://codechina.gitcode.host/programmer/heti-test/2-58-app-architecture.html",
"chapter_limited_page_url": "https://codechina.gitcode.host/programmer/heti-test/2-58-app-architecture.html"
}...
]
},
{
"title":"结束词",
"sub_title":"结束词,布拉布拉",
"description":"万维网发明人 Tim Berners-Lee 谈到设计原理时说过:“简单性和模块化是软件工程的基石",
"index":"1",
"chapters":[
{
"id": "10",
"title": "安居客 Android 模块化探索与实践",
"sub_title": "文/张磊",
"index": "10",
"free_rate": "0",
"description": "万维网发明人 Tim Berners-Lee 谈到设计原理时说过:“简单性和模块化是软件工程的基石;分布式和容错性是互联网的生命。”由此可见模块化之于软件工程领域的重要性。本文以安居客为例,分享笔者在模块化探索实践方面的一些经验。",
"chapter_page_url": "https://codechina.gitcode.host/programmer/heti-test/10-anjuke-and-android.html",
"chapter_limited_page_url": "https://codechina.gitcode.host/programmer/heti-test/10-anjuke-and-android.html"
}
]
}
]
}
id
:唯一ID
title
:章节标题
sub_title
:副标题
index
:章节排序
description
:章节描述
chapter_page_url
:章节内容页面地址
正文
GET web_url
https://codechina.gitcode.host/programmer/10-years-of-mobile-dev/1-10-years-ios-and-android.html
首页(master 版本)
GET /api/v4/projects/codechina%2Fprogrammer%2Fprogramer_magazine_list/repository/files/index.json/raw?ref=master
{
"id": "1",
"title": "《移动开发十年》",
"sub_title": "程序员 2.0 第一期",
"path": "codechina/programmer/10-years-of-mobile-dev",
"ref": "master",
"detail": "detail.json",
"chapters": "chapters.json",
"index_image": "https://images.gitbook.cn/Fg_-eDnBvuAVxBrBv2vjzMpQ3e3E",
"index_video": "https://live.csdn.net/v/embed/34453",
"original_price": "19.9",
"line_price": "19.9",
"sale_price": "9.9",
"selected_chapters": [
{
"id": "6",
"title": "58同城 iOS 客户端搜索模块组件化实践",
"sub_title": "文/周俊杰",
"icon_image": "https://images.gitbook.cn/FhXlVyrlnaV15FWN-evtoWLvxAZD",
"index": "6",
"free_rate": "100",
"description": "Android 视频相关的开发,大概一直是整个 Android 生态、以及 Android API 中,最为分裂以及兼容性问题最为突出的一部分,本文从视频编码器的选择和如何对摄像头输出的 YUV 帧进行快速预处理两方面,从实践角度解析笔者曾趟过 Android 视频编码的那些坑,希望对广大读者有所助益。",
"chapter_page_url": "https://codechina.gitcode.host/programmer/10-years-of-mobile-dev/6-58-ios-search.html",
"chapter_limited_page_url": "https://codechina.gitcode.host/programmer/10-years-of-mobile-dev/6-58-ios-search.html"
},
{
"id": "7",
"title": "饿了么商家版 iOS 端订单模块的重构之路",
"sub_title": "",
"icon_image": "https://images.gitbook.cn/FhXlVyrlnaV15FWN-evtoWLvxAZD",
"index": "7",
"free_rate": "20",
"description": "",
"chapter_page_url": "https://codechina.gitcode.host/programmer/10-years-of-mobile-dev/7-wechat-develop-cache-2.html",
"chapter_limited_page_url": "https://codechina.gitcode.host/programmer/10-years-of-mobile-dev/7-wechat-develop-cache-2.html"
},
{
"id": "8",
"title": "稳定性与内存优化――小型团队的 Android 应用质量保障之道",
"sub_title": "文/何红辉",
"index": "8",
"free_rate": "0",
"description": "对于小型创业公司来说,没有 BAT 等大厂里的测试平台、方案研究员,QA 资源相对有限,如果将一切发现问题的重担都交给测试部门,不但耗费的测试周期长,而且有一些问题将难以发现。本文作者基于此分享了他们是如何保证应用的稳定性、避免内存泄漏的,希望能够帮助大家在开发过程中少走弯路。",
"chapter_page_url": "https://codechina.gitcode.host/programmer/10-years-of-mobile-dev/8-small-team-and-andriod.html",
"chapter_limited_page_url": "https://codechina.gitcode.host/programmer/10-years-of-mobile-dev/8-small-team-and-andriod.html"
}
],
"short_description": "我们特别组织了数十位开发者,一方面,是十年改变与回顾...",
"description": "<div id=\"content_views\" class=\"htmledit_views\">\n ...",
"author": {
"username": "programmer",
"user_title": "国内开发者的权威刊物",
"nickname": "程序员杂志编辑组"
}
}
id
:刊物唯一ID(由编辑人员自行定义,如:1)
title
:刊物标题
sub_title
: 副标题
path
:刊物在 code 上的路径(刊物在 code 平台的唯一标识之一,关键字段,可作为项目id使用,使用时必须将 \
转译为 %2F
)
detail
:详情文件(由编辑定义,协议定为:detail.json
,程序需根据实际值使用,不可直接采用 detail.json
)
chapters
:章节文件(协议定为:chapters.json
)
ref
:分支(必要字段,默认为:master
)
index_image
:首页图
index_video
: 首页视频
original_price
:原价
line_price
:划线价格
sale_price
:售价
selected_chapters
: 严选章节(与普通章节数据区别在于可能会包含 icon_image
)
short_description
:短描述
description
: 描述 html
author
:作者
-
username
:用户名 -
user_title
:用户 title -
nickname
:昵称
首页(stable-v2版本)
正式地址:
GET /api/v4/projects/codechina%2Fprogrammer%2Fprogramer_magazine_list/repository/files/index.json/raw?ref=stable-v2
测试地址:
GET /api/v4/projects/codechina%2Fprogrammer%2Fprogramer_magazine_list/repository/files/index.json/raw?ref=develop
{
"magazines": [//轮播杂志
{
"id": "1",
"title": "《开发者黄金十年》",
"sub_title": "《新程序员》第一期",
"path": "new-programmer/2021-01",
"ref": "master",
"detail": "detail.json",
"chapters": "chapters.json",
"index_image": "https://img-home.csdnimg.cn/images/20210525124123.png",
"index_video": "",
"original_price": "48.0",
"line_price": "48.0",
"sale_price": "48.0",
"short_description": "",
"description": "",
"author": {
"username": "programmer",
"user_title": "国内开发者的权威刊物",
"nickname": "程序员杂志编辑组"
}
},..
],
"selected_chapters": [//精选章节
{
"id": "9",
"title": "对话Linus Torvalds:Linux 30年",
"sub_title": "",
"icon_image": "https://img-blog.csdnimg.cn/20210528131454954.jpeg",
"index": "9",
"magazine_id": "1",
"path": "new-programmer/2021-01",//增加杂志路径分支等信息
"ref": "master",
"detail": "detail.json",
"chapters": "chapters.json",
"free_rate": "100",
"description": "",
"chapter_page_url": "https://new-programmer.gitcode.host/2021-01/25.html",
"chapter_limited_page_url": ""
},...
{
"id": "31",
"title": "走近低代码:人人都是开发者时代来临?",
"sub_title": "",
"icon_image": "https://img-blog.csdnimg.cn/20210528131457969.png",
"index": "31",
"magazine_id": "1",
"path": "new-programmer/2021-01",
"ref": "master",
"detail": "detail.json",
"chapters": "chapters.json",
"free_rate": "20",
"description": "",
"chapter_page_url": "https://new-programmer.gitcode.host/2021-01/8.html",
"chapter_limited_page_url": "https://new-programmer.gitcode.host/2021-01/8-limit.html"
}
]
}