官术网_书友最值得收藏!

Listing all comments for a particular post

  • Request: GET /posts/1/comments HTTP/1.1
  • Response:
{
data:[
{
id:1, comment:"Awesome Post", post_id:1, link: "/comments/1"
}, {
id:2, comment:"Another post comment", post_id:1, link: "/comments/2"
}
],
total_count: 2,
limit: 10,
pagination: {
first_page: "/posts/1/comments?page=1",
last_page: "/posts/1/comments?page=1",
page=1
}
}
  • Response Code: 200 OK

As you can see, a post's comments listing is very similar to a blog post's listing. And it has total_count and pagination in the same way. It shows the first and last page right now because total_count for the records is only 2. So there is no next or previous page. Otherwise, we should also have to show the next and previous links in pagination.

Normally, you don't see pagination with comments on blogs, but it is better to keep it consistent to have pagination in the listing. Because there can be lot of comments for a post, we should apply some limit to it, so we will need pagination.

主站蜘蛛池模板: 东乡县| 南郑县| 登封市| 明水县| 淮阳县| 上高县| 平舆县| 长葛市| 荣昌县| 大关县| 临泽县| 手游| 维西| 兴海县| 北流市| 余干县| 岳西县| 岫岩| 大厂| 婺源县| 茶陵县| 庆安县| 延庆县| 十堰市| 格尔木市| 鹤壁市| 屏东市| 新安县| 永宁县| 大连市| 晋州市| 长岭县| 松潘县| 松原市| 东辽县| 龙胜| 遂宁市| 温泉县| 天津市| 镇赉县| 辉县市|