小编Mik*_*aki的帖子

如何在遵循REST的同时在HAL(JSON版本)中表示集合

假设我有一系列书籍,我们称之为图书馆.GET domain.com/library应该以符合HAL标准的JSON返回库中的书籍列表.我该如何格式化JSON?我怎么能嵌入书籍资源?这是我目前正在考虑的格式:

{
  "books": [
      {
          "name": "Fight Club",
          "_links": {
              "self": { 
                  "href": "domain.com/library/Fight-Club"
              },
           },
           ...
      },
       ....
  ],
  "_links" : {
       "search": { 
           "href": "domain.com/library/search"
       },
       ...
   },
   "_embedded" : {
       "Fight Club": {
           "author": "Chuck Palahniuk",
           ...
           [Same links as above]
       }
   }
}
Run Code Online (Sandbox Code Playgroud)

rest json web-services hateoas web

7
推荐指数
1
解决办法
3049
查看次数

标签 统计

hateoas ×1

json ×1

rest ×1

web ×1

web-services ×1