- 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.
推薦閱讀
- 企業級Java EE架構設計精深實踐
- Visual Basic 6.0程序設計計算機組裝與維修
- SpringMVC+MyBatis快速開發與項目實戰
- Vue.js 3.0源碼解析(微課視頻版)
- MATLAB實用教程
- Python程序設計
- C語言程序設計
- RabbitMQ Cookbook
- Vue.js 2 Web Development Projects
- Django實戰:Python Web典型模塊與項目開發
- Building Business Websites with Squarespace 7(Second Edition)
- Java程序設計教程
- 體驗之道:從需求到實踐的用戶體驗實戰
- jMonkeyEngine 3.0 Beginner’s Guide
- 面向物聯網的Android應用開發與實踐