Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disjoint resources with same relation in json-home documents #225

Open
jackfirth opened this issue Apr 17, 2017 · 5 comments
Open

Disjoint resources with same relation in json-home documents #225

jackfirth opened this issue Apr 17, 2017 · 5 comments

Comments

@jackfirth
Copy link

Say I have three completely different resources A, B, and C that are all described by some relation X (possibly a very general relation such as "hosts"). In a JSON Home document, there seems to be two ways to link to these resources:

  • With a URI template as a Resource Template. This can easily be inappropriate, as the resources may have very different URI structures, supported formats, authentication hints, etc. etc.
  • With multiple entries in the "resources" object that all have the same relation, e.g. {X: A, X: B, X:C. While this is technically acceptable in the JSON spec, many client implementations don't handle it well and the JSON Home spec implies that non-templated entries in the "resources" object are the only entries with a particular relation:

A Resource Object links to resources of the type indicated in their name using one of two mechanisms; either a direct link (in which case there is exactly one resource of that relation type associated with the API), or a templated link, in which case there are zero to many such resources.

This makes it difficult for me to build tools consuming JSON Home documents, as I was planning on using more standard relations and tool-specific relations that describe a variety of resources rather than primarily API-specific relations, to make tools that work across multiple APIs. I was expecting an array of resources and resource templates for each relation rather than a single resource or template.

@mnot
Copy link
Owner

mnot commented Apr 19, 2017

Can you give me some more detail about your use case? I'm trying to understand how you want to use the spec.

@mnot mnot added the json-home label Apr 26, 2017
@dret
Copy link
Contributor

dret commented Oct 10, 2017

it seems that this is a valid point, and one issue that tends to surface in certain ways of representing links in JSON. some designs then go the route of changing the JSON structure so that they can accommodate multiple links of the same relation.
i am not saying that JSON home has to do this. but it might be useful to add some informative text that makes this limitation of the format explicit, so that people are not left wondering.
one use case i could easily think about would be to say that there is more than one associated documentation resource available. service-doc then would repeat as a link relation, and these links could be further qualified by media type hints, one linking to HTML documentation and the other to a PDF version (this example probably applies best to the API object, which has the same limitation).

@handrews
Copy link

We're struggling a bit with this in JSON Hyper-Schema as well. Currently, our links is an array of objects (which may use URI Templates), so multiple objects in the array can have the same rel. However, some prefer rel as an object key, which would probably result in the values being a list of objects, which doesn't simplify things all that much IMHO.

As for use cases, you may want to link to resources in multiple other systems. For instance, links from a person to "publications" of various sorts that are not all hosted by the same other service. Some may not be online and may be better identified by URNs than URLs.

Off the top of my head I can't come up with a use case within a single API where the same entity designs all of the URIs, but I just woke up and the caffeine hasn't really kicked in yet :-P

@jackfirth
Copy link
Author

jackfirth commented Oct 11, 2017

I lost track of this issue, whoops.

A specific tool I had in mind when I wrote this was a hypothetical command line tool that could do some generic CRUD operations on any REST API with a home document that linked to collections that should support CRUD operations. There'd be some link relation defined by the tool, maybe an http url to the tool's docs or something, and each link with that relation would equal one collection. Forcing a server to ensure the collections all fit a particular URI template just to get this tool integration working seems restrictive.

To deal with this specific problem, I'd probably just have the home document link to a single resource that represents a list of links to use as collections. So it's more of an inconvenience of the format for me than a blocking issue.

@dret
Copy link
Contributor

dret commented Oct 11, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants