- Building RESTful Web Services with PHP 7
- Haafiz Waheed ud din Ahmad
- 196字
- 2021-07-03 00:02:20
Listing all blog posts
- Request: GET /posts HTTP/1.1
- Response:
{
data:[
{
id:1, title:"Awesome Post", content:"This is an awesome post", link: "/posts/1"
},
{
id:2, title:"Amazing one", content:"This is an amazing post", link: "/posts/2"
}
],
total_count: 2,
limit:10,
pagination: {
first_page: "/posts?page=1",
last_page: "/posts?page=1",
page=1
}
}
- Response code: 200 OK
Here, data is an array of objects as there are multiple records returning. Other than total_count, there is a pagination object as well, and right now it shows the first and last pages because total_count for records is only 2. So, there is no next or previous page. Otherwise, we should also have to show the next and previous in pagination.
As you can see, there are links in the pagination as well as the post's links in post objects. We have included these links in response to being compliant with the HATEOAS constraint, which stated that if the client knows about an entry point, it should be enough to discover relevant endpoints.
Here, we explored the requirements of blog posts and defined the request and response of their endpoints. In the next entity/resource, we are going to define endpoints and responses in comments.
- 軟件項目估算
- 大學計算機基礎(第三版)
- Building a Game with Unity and Blender
- 單片機C語言程序設計實訓100例:基于STC8051+Proteus仿真與實戰(zhàn)
- PHP+MySQL+Dreamweaver動態(tài)網站開發(fā)實例教程
- 軟件架構:Python語言實現
- 深入淺出RxJS
- 手把手教你學C語言
- C語言程序設計實驗指導 (第2版)
- Visualforce Developer’s guide
- Windows Embedded CE 6.0程序設計實戰(zhàn)
- Modern C++ Programming Cookbook
- 計算機應用技能實訓教程
- ABAQUS6.14中文版有限元分析與實例詳解
- Java程序設計入門(第2版)