Confusion on relationships in author example

{
  "type": "articles",
  "id": "1",
  "attributes": {
    "title": "Rails is Omakase"
  },
  "relationships": {
    "author": {
      "links": {
        "self": "/articles/1/relationships/author",
        "related": "/articles/1/author"
      },
      "data": { "type": "people", "id": "9" }
    }
  }
}

Looking at this example I see that there is a “people” resource with id “9” and that that “people” is the author of this comment. I don’t see any hints on where I need to go to look up people/9 in the links. I’m also curious if this article had multiple authors, like say people/9 plus chatGPT and I had it listed out as:

{
  "type": "articles",
  "id": "1",
  "attributes": {
    "title": "Rails is Omakase"
  },
  "relationships": {
    "authors": {
      "links": {
        "self": "/articles/1/relationships/author",
        "related": "/articles/1/author"
      },
      "data": [
        { "type": "people", "id": "9" },
        { "type": "ai", "id": "2" }
    }
  }
}

How might I provide links to both my people/9 resource and ai/2 resource?

My first thought was that there should be a people and ai links type

{
  "type": "articles",
  "id": "1",
  "attributes": {
    "title": "Rails is Omakase"
  },
  "relationships": {
    "authors": {
      "links": {
        "self": "/articles/1/relationships/author",
        "related": "/articles/1/author",
        "people": "/people",
        "ai": "/ai"
      },
      "data": [
        { "type": "people", "id": "9" },
        { "type": "ai", "id": "2" }
    }
  }
}```

If you want to fetch the related resources, you can do a GET request to the related link of the relationship. Using that URL has the benefit that it returns the current state. That means it could also be used to reload related authors in case it may have changed.

The resource identifiers provided under data member are primarily meant to link resources within a document. That’s why it’s also called resource linkage.

Additionally a client may use them to

  • identify if it’s a has-one or has-many relationship,
  • if a resource is attached to it and in case of has-many how many resources are attached to it, and
  • mapping it to existing resource data in local cache.

Resource identifier objects are not meant to fetch the resources.

1 Like

So in the above example, author should be plural since it is transitioning to a to-many, and a GET to /articles/1/authors should return both the /people/9 and /ai/2 resources within the top level data response?

If an article should have multiple authors and if an author could be either a person or an artificial intelligence in your domain: yes.

1 Like

Continuing the discussion from Confusion on relationships in author example: