Self vs. related links (and what to return)

Thanks for clarifying @dgeb

To fully summarise this thread for future readers, imagine having an articles document like:

{
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!"
    },
    "links": {
      "self": "http://example.com/articles/1"
    },
    "relationships": {
      "author": {
        "links": {
          "self": "http://example.com/articles/1/relationships/author",
          "related": "http://example.com/articles/1/author"
        },
        "data": {
          "type": "people",
          "id": "9"
        }
      }
    }
  }
}

In this case following the author relationship self link (http://example.com/articles/1/relationships/author) should return:

{
  "data": {
    "type": "people",
    "id": "9"
  },
  "links": {
    "self": "http://example.com/articles/1/relationships/author",
    "related": "http://example.com/articles/1/author"
  }
}

Following the author relationship related link (http://example.com/articles/1/author) should then return:

{
  "data": {
    "type": "people",
    "id": "9",
    "attributes": {
      "first-name": "Dan",
      "last-name": "Gebhardt",
      "twitter": "dgeb"
    },
    "links": {
      "self": "http://example.com/people/9"
    },
  },
  "links": {
    "self": "http://example.com/articles/1/author",
  }
}

Let me know if you think something is wrong with this.

5 Likes