- Building RESTful Web Services with PHP 7
- Haafiz Waheed ud din Ahmad
- 159字
- 2021-07-03 00:02:21
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.
推薦閱讀
- Go Web編程
- FreeSWITCH 1.8
- 神經網絡編程實戰:Java語言實現(原書第2版)
- jQuery從入門到精通 (軟件開發視頻大講堂)
- INSTANT Adobe Edge Inspect Starter
- 基于SpringBoot實現:Java分布式中間件開發入門與實戰
- ScratchJr趣味編程動手玩:讓孩子用編程講故事
- Android應用開發實戰
- Python開發基礎
- 工業機器人離線編程
- Mastering Gephi Network Visualization
- IPython Interactive Computing and Visualization Cookbook
- Hands-On Robotics Programming with C++
- 軟件測試技術
- C語言程序設計教程