官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 金昌市| 齐齐哈尔市| 龙川县| 平山县| 襄垣县| 响水县| 罗源县| 二连浩特市| 焦作市| 阿拉善右旗| 方城县| 永修县| 克东县| 永昌县| 格尔木市| 白银市| 阳江市| 法库县| 天津市| 即墨市| 凌源市| 连平县| 大城县| 昭觉县| 深圳市| 丹东市| 陆河县| 泰来县| 邹平县| 股票| 固始县| 安宁市| 健康| 武宁县| 沿河| 松阳县| 涟源市| 永顺县| 泸州市| 前郭尔| 庄河市|