我们在前面的教程里面介绍了剑鱼论坛API的基础知识,从这篇开始我们将详细介绍每个API的用法。
这篇我们来介绍如何通过API来获取帖子列表。
请求方式:GET
请求地址:http://域名/api
请求数据:{"post": "all"}
返回数据:
{
"data": [
{
"type": "posts",
"id": "3",
"attributes": {
"title": "标题",
"summary": "摘要",
"body": "正文",
"created": "创建时间",
"updated": "更新时间",
"comments": 0,
"reading": 0,
"fine": 0,
"annex": 0,
"image": "图片地址",
"video": "视频地址"
},
"links": {
"self": "本帖链接地址"
},
"relationships": {
"author": {
"data": {
"type": "people",
"id": "1",
"attributes": {
"nickname": "作者昵称",
"avatar": "作者头像地址"
}
}
}
}
},
......更多项
],
"links": {
"self": "当前页地址",
"first": "第一页地址",
"last": "最后一页地址",
"prev": "上一页地址",
"next": "下一页地址"
}
}
这里的请求头Accept必须设置为“application/vnd.api+json”,这个在前面的基础介绍里面已经提到过,以后的教程就不再重复提及了。
我们还可以直接使用“http://域名/api/post/all”这样的请求地址来获取数据。