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

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.

主站蜘蛛池模板: 宜宾县| 涟源市| 通化市| 新乡县| 平阴县| 民权县| 黄冈市| 平潭县| 卓资县| 景泰县| 临潭县| 临桂县| 大新县| 福州市| 河北省| 彭州市| 蒲江县| 台南市| 德兴市| 山阳县| 建德市| 沐川县| 涞水县| 高密市| 延川县| 沛县| 儋州市| 哈巴河县| 邛崃市| 巫溪县| 湟源县| 图木舒克市| 河南省| 象州县| 南雄市| 兴文县| 遂平县| 文登市| 玉林市| 萍乡市| 许昌市|