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

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.

主站蜘蛛池模板: 宜昌市| 兴文县| 巫山县| 京山县| 五原县| 西安市| 延安市| 迭部县| 三门峡市| 宁远县| 原阳县| 林西县| 瓦房店市| 屏边| 彝良县| 雷山县| 平果县| 江城| 泸州市| 凤台县| 称多县| 河东区| 绵竹市| 北辰区| 义乌市| 清涧县| 昌图县| 南开区| 山东| 原平市| 嘉黎县| 神池县| 汉川市| 博爱县| 崇左市| 福泉市| 河池市| 江永县| 麻城市| 龙山县| 长兴县|