Problem/Motivation

We now have a way for Entities to define link relationships they support; the most notable is canonical, but it can define any other IANA-defined relationship. We then automatically add those relationships in various places, and intend to do so for REST plugins on Entity at least.

However, that only works for the IANA-standardized relationships. In reality, any serious RESTful API is going to need to define custom relationships. It is not correct however to simply throw additional link names around willy nilly. That leads to collisions and confusion. Rather, they need to be namespaced. Namespaces are expected to be a URI. So you'd end up with something like this:

http://drupal.org/rels/owner = http://drupal.org/user/5

(for a link that points to a node owner from a node resource)

That's ugly, of course. Instead, the common way to do that is with a curie alias. (I'm sure Lin Clark can correct my overly simplistic explanation here.) Essentially, you shorten the namespace to a simple string and provide a lookup for it that points to human-friendly documentation. So:

drupal:owner = http://drupal.org/user/5 
curies = [
http://drupal.org/rels/{rel}, name="drupal"
]

And then http://drupal.org/rels/owner would contain documentation on what "owner" means.

Not only do we have no defined namespace, we also have no way for any modules to define links within that namespace. If people want to build out well-behaved REST-style APIs on Drupal, they're going to need a way to properly define and use extra link relationships.

Proposed resolution

What we need is a way to let modules:

1) Define new link relationships
2) Associate a link to a given REST resource (which could be an entity or not)
3) Add additional links to a resource
4) Automate a way to expose the aforementioned documentation/curie.

How we do that is an open question. In Drupal 7 the knee-jerk response would have been "info hook!", but that's not a good approach in Drupal 8. The natural next knee-jerk response is "plugins!", but I'm not convinced that's right either. (It may be, though.) We should figure this out, and then implement it.

Remaining tasks

Figure out an API here, then implement it..

User interface changes

Likely none.

API changes

This should be possible with no changes to existing APIs, just additional functionality that is currently sorely missing.

#1925618: Ensure Drupal's web services are self-documenting: Swagger support OR rest_api_doc to Drupal core as an experimental module?
#2019123: Use the same canonical URI paths as for HTML routes

Comments

Crell’s picture

Issue summary: View changes

Fix bad rendering of code sample.

Crell’s picture

Issue summary: View changes

Correct typos.

linclark’s picture

Issue summary: View changes

Removed colon from path part of URI.

linclark’s picture

I would prefer using the full URI here instead of CURIE syntax. Yes, full URIs are verbose and ugly... but it is also entirely clear what they are.

Unfortunately, CURIEs tend to confuse people a lot. There has been an effort to document the problem with the indirection that prefix mechanisms introduce:

If we do decide to use CURIEs, then the (in-process) CURIE support in RDF module should probably be abstracted out to the main system so that both can use it. See #1778410: Throw exception when RDF namespaces collide.

Crell’s picture

Problems with using full URI relationships:

* Links get ugly.
* Links could get confusing for people who don't get it. A links array in an entity header like this:

links = {
  "canonical" = "/node/{node}",
  "http://drupal.org/rels/add-form" = "/node/add/{entityType}"
}

Even confuses me a little, and I get what is going on. That could well confuse less RESTifarian developers even more.

Benefits of using full URI relationships:

* Sounds like it's way easier to implement
* It's just an opaque string, so from a computer POV it's no different.

Whether we use CURIEs or full URI relationships, we probably do need some way to pre-define them if only so there's a place for documentation to live.

Crell’s picture

Issue summary: View changes

Updated issue summary.

Crell’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

Duplicate of #2113345: Define a mechanism for custom link relationships, which has the better proposal for how to move forward.