- 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.
推薦閱讀
- C語言程序設(shè)計(jì)教程
- Mastering Visual Studio 2017
- OpenDaylight Cookbook
- PHP 從入門到項(xiàng)目實(shí)踐(超值版)
- C#編程入門指南(上下冊)
- Python語言程序設(shè)計(jì)
- 神經(jīng)網(wǎng)絡(luò)編程實(shí)戰(zhàn):Java語言實(shí)現(xiàn)(原書第2版)
- Cocos2d-x學(xué)習(xí)筆記:完全掌握Lua API與游戲項(xiàng)目開發(fā) (未來書庫)
- 利用Python進(jìn)行數(shù)據(jù)分析(原書第3版)
- Creating Stunning Dashboards with QlikView
- Learning Material Design
- Raspberry Pi Robotic Blueprints
- Practical Responsive Typography
- Learn C Programming
- 大話C語言