2

I am trying to understand the nuances between the use of Relation Types and Link's with a Name property.

Perhaps an example will best illustrate my question. Consider a HAL formatted response representing a peer reviewed article:

  {
    name: "Mechanics (Le mecaniche)",
    _links : {
      canonical : { href: "https://phys.org/articles/Mechanics"},
      "x:author" : [
         { href : "https://phys.org/authors/111", title : "Galileo Galilei"}
      ],
      "x:reviewer" : [
         { href : "https://phys.org/authors/222", title : "Isaac Newton"}
      ]
    }
  }

The key thing I'm trying to show with this example is that the article resource contains more than one semantically different relationship to the same type of resource. In this example, the article has a link to an author who is the author of the article as well as a link to an author who performed a peer review of the article.

In the above example, I defined those as two different Relation Types. Based on my read of the HAL spec and the Web Linking spec, the above approach is both valid and consistent with many examples.

BUT... What if I formatted the same response as follows:

  {
    name: "Mechanics (Le mecaniche)",
    _links : {
      canonical : { href: "https://phys.org/articles/Mechanics"},
      "x:author" : [
         { name = "author", href : "https://phys.org/authors/111", title : "Galileo Galilei"},
         { name = "reviewer", href : "https://phys.org/authors/222", title : "Isaac Newton"}
      ]
    }
  }

In this example, I chose to use the Relation Type to indicate the resource type and deferred to the Link's Name property to narrow the relationships meaning.

I find the latter approach appealing from a pragmatic perspective. I can imagine the author of a client application using the Relation Type as the key to a resource cache. In this case, the client would have a single cache of Author resources instead of independent author and reviewer caches with duplicated entries (where an author is also a reviewer.) I realize that a single heterogeneous resource cache would obviate this and/or pushing cache responsibility to the browser (where it should be IMHO), BUT ... again, this is the pragmatic perspective. Many web-apps handle caching internally and want a cache per resource type (perhaps to apply different policies by resource type.)

I also like the latter approach because I can utilize the link's name property "as a secondary key for selecting Link Objects which share the same relation type", per the HAL spec. I can't help but to read that line from the spec as "...the same resource type."

Last but not least, I'm wondering how either approach would impact the documentation of these links. Specifically, as "Extension Relation Types" the 'x:author' and 'x:reviewer' relation types should have documentation available at their url (directly or via CURIE.) If I followed the latter approach, using link name properties, then the documentation would need sub-sections that describe that named variant of the resource relation.

I've done a bit of searching and I haven't found any examples of the use of a link's name property. I'd love to see some, and/or to hear more from the author about the intent of that field.


Update..

The responses so far have emphasized that the relation type is intended to reflect the relationship between the context and the result at the href, and not the type of resource at that destination.

That's understandable, but if possible, please elaborate on the purpose of a Link's Name property. What is an example of its use that distinguishes it from the Relation Type?

Community
  • 1
  • 1
allenru
  • 697
  • 6
  • 22
  • A resource does not have a type as you might think. A collection is only a set of data that is mapped to a representation format understood by the client. This is what content-type negotiation is all about. If you think of resources having a specific type, the client might break if the server ever decides to send out anything other than the client expects. By definition (Fieldings thesis) REST aims at minimizing latency while at the same time maximizes independence and scalability of the server/API. The constraints imposed exactly target these – Roman Vottner Feb 19 '19 at 16:42
  • Excellent feedback so far. If someone can provide an example of a good use case for a Link with a name property, then I'll consider this question answered. Understanding when the name property should be used, is the 'essence' of this question. – allenru Feb 22 '19 at 19:26

2 Answers2

1

You can do the second as long as you don't attach semantics to the name. Unfortunately x:author seems to be misleading in the second scenario because we wouldn't normally consider a reviewer to be an author.

Your original stated goal "contains more than one semantically different relationship to the same type of resource" can be achieved by using two link relation types and then using metadata in the returned representation to inform the client that the two representations are the same type. I'm not sure there is a clean way that you can embed the type of the target into the context document. That's usually not a very HTTP friendly way of doing things.

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
1

Even though you consider the two people to be 'authors', their relationship to the main resource is not 'author'.

Link relationship types should describe not "what kind of resource the linked resource is" but rather "what relationship the linked resource has to the context resource".

Evert
  • 93,428
  • 18
  • 118
  • 189