嵌套外键关系

序列化的外键关系通常建立在一个有嵌套关系的对象之上, 例如.:

  1. {
  2. "name": "service-production",
  3. "owner": {
  4. "id": "5d8201b0..."
  5. },
  6. ...
  7. }

而不是这样 例如:

  1. {
  2. "name": "service-production",
  3. "owner_id": "5d8201b0...",
  4. ...
  5. }

这种方式尽可能的把相关联的资源信息内联在一起,而不用改变响应资源的结构,或者展示更高一级的响应区域, 例如:

  1. {
  2. "name": "service-production",
  3. "owner": {
  4. "id": "5d8201b0...",
  5. "name": "Alice",
  6. "email": "alice@heroku.com"
  7. },
  8. ...
  9. }