- 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.
推薦閱讀
- SQL Server 從入門到項目實踐(超值版)
- C語言程序設計案例教程(第2版)
- Learning Apex Programming
- Testing with JUnit
- Visual Basic程序設計(第3版):學習指導與練習
- 機器人Python青少年編程開發實例
- Java Web基礎與實例教程
- KnockoutJS Starter
- Swift 4 Protocol-Oriented Programming(Third Edition)
- Orleans:構建高性能分布式Actor服務
- Python機器學習算法與應用
- PHP+MySQL動態網站開發從入門到精通(視頻教學版)
- JavaScript編程精解(原書第2版)
- iOS Development with Xamarin Cookbook
- C語言程序設計實驗指導與習題精解