我们在《剑鱼论坛怎么通过API获取帖子列表》中介绍了怎么用API获取帖子列表,这一篇继续介绍如何获取单独一篇帖子的方法。
请求方式:GET
请求地址:http://域名/api
请求数据:{"post": "1"}
这里的请求数据里面的“1”是帖子的id号,如果要获取id号为2的帖子,那么这里填“2”,以此类推。
返回数据:
{
"data": [
{
"type": "posts",
"id": "1",
"attributes": {
"title": "标题",
"body": "正文",
"created": "创建时间",
"updated": "更新时间",
"comments": 0,
"reading": 0,
"like": 0,
"dislike": 0,
"keep": 0,
"fine": 0,
"video": "视频地址",
"source": "来源",
"annex": "附件地址"
},
"links": {
"self": "当前帖子的地址"
},
"relationships": {
"author": {
"data": {
"type": "people",
"id": "1",
"attributes": {
"nickname": "作者昵称",
"avatar": "头像地址"
}
}
}
}
}
]
}
跟获取帖子列表类似,我们还可以用“http://域名/api/post/1”这样的请求方式来获取数据。