REST - 资源和集合表示 [英] REST - Resource and Collection Representations

查看:28
本文介绍了REST - 资源和集合表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对收藏资源的设计感到困惑.假设我有一个用户资源 - 如下所示.<代码><预>http://www.example.com/users/{user-id}用户:{ID : "",名称 : "",年龄 : "",地址:[{第 1 行:",第2行:",城市 : "",状态 : "",国家 : "",压缩 : ""}]}

现在,我的用户集合资源表示应该如何?它应该是用户表示的列表(如上所述)吗?或者它可以是如下所示的子集:<代码><预>http://www.example.com/users/用户:[{ID : "",名称 : "",关联 : {rel : "自我",href : "/users/{id}"}}]

集合资源表示应该包括包含资源的完整表示还是可以是一个子集?

解决方案

媒体类型定义了如何传达信息的规则.查看Collection+JSONHAL 示例,了解如何做您想做的事情.

I have a confusion with the design of collection resources. Let's say I have a user resource - represented as below.

http://www.example.com/users/{user-id}
user : {
  id : "",
  name : "",
  age : "",
  addresses : [
    {
      line1 : "",
      line2 : "",
      city : "",
      state : "",
      country : "",
      zip : ""
    }
  ]
}

Now, how should my users collection resource representation be? Should it be a list of user representations (as above)? Or can it be a subset of that like below:

http://www.example.com/users/
users : [
  {
    id : "",
    name : "",
    link : {
      rel : "self",
      href : "/users/{id}"
    }
  }
]

Should the collection resource representation include the complete representation of the containing resources or can it be a subset?

解决方案

Media types define the rules on how you can convey information. Look at the specifications for Collection+JSON and HAL for examples of how to do what you are trying to do.

这篇关于REST - 资源和集合表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆