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

More consistent resource linkage. #447

Merged
merged 1 commit into from
Mar 11, 2015
Merged

More consistent resource linkage. #447

merged 1 commit into from
Mar 11, 2015

Conversation

dgeb
Copy link
Member

@dgeb dgeb commented Mar 10, 2015

I put together this PR as the result of a discussion in #437. As I mentioned, this was one approach that I considered while working on RC2, but was concerned with the verbosity.

However, after discussing with a couple implementors who are in favor of these simplifications, I'd like to put this out there for general consideration. Even though this is the 11th hour for the spec, it's probably worthwhile to consider a simplifying approach.

The gist is that resource linkage is consistently represented in this approach, regardless of whether relationships are homogeneous or heterogeneous. Linkage is contained within a linkage member in the links object, eliminating the dichotomy of using either type / id (for homogeneous relationships) vs. data (for heteregeneous relationships).

Here's the home page resource object currently:

  "data": [{
    "type": "posts",
    "id": "1",
    "title": "JSON API paints my bikeshed!",
    "links": {
      "self": "http://example.com/posts/1",
      "author": {
        "self": "http://example.com/posts/1/links/author",
        "related": "http://example.com/posts/1/author",
        "type": "people",
        "id": "9"
      },
      "comments": {
        "self": "http://example.com/posts/1/links/comments",
        "related": "http://example.com/posts/1/comments",
        "type": "comments",
        "id": ["5", "12"]
      }
    }
  }]

And here it is after this change:

  "data": [{
    "type": "posts",
    "id": "1",
    "title": "JSON API paints my bikeshed!",
    "links": {
      "self": "http://example.com/posts/1",
      "author": {
        "self": "http://example.com/posts/1/links/author",
        "related": "http://example.com/posts/1/author",
        "linkage": {"type": "people", "id": "9"}
      },
      "comments": {
        "self": "http://example.com/posts/1/links/comments",
        "related": "http://example.com/posts/1/comments",
        "linkage": [
           {"type": "comments", "id": "5"},
           {"type": "comments", "id": "12"}
        ]
      }
    }
  }]

I find this structure to be more consistent with resource objects themselves, which all must contain a type and id. This approach also simplifies endpoints for updating relationships.

But of course, as I've said, it is more verbose.

@dgeb dgeb added this to the 1.0 milestone Mar 10, 2015
@bintoro
Copy link
Contributor

bintoro commented Mar 10, 2015

In favor 👍

A further benefit not mentioned in @dgeb's comment is that this eliminates the need to maintain a separate format for relationship URL representations.

@tkellen
Copy link
Member

tkellen commented Mar 10, 2015

👍 here too.

Resource linkage is consistently represented in a `linkage` member
within each link object. This simplifies the rules for resource linkage
across homogeneous and heterogeneous relationships.
@lgebhardt
Copy link
Contributor

👍 from me too

@hhware
Copy link
Contributor

hhware commented Mar 10, 2015

IMHO, a great improvement!

@ColtonProvias
Copy link
Contributor

Also in favor.

@gr0uch
Copy link
Contributor

gr0uch commented Mar 10, 2015

It should have been this way from the start if you wanted to support heterogeneous relationships. +1

@nwjsmith
Copy link
Contributor

I think the trade-off in verbosity is fine if it means better consistency. This also might make it easier to write a client-side caching that looks up by a key based on type and id.

🚀

@dgeb
Copy link
Member Author

dgeb commented Mar 11, 2015

With all in favor and no objections, I'm merging.

dgeb added a commit that referenced this pull request Mar 11, 2015
More consistent resource linkage.
@dgeb dgeb merged commit 4af7944 into gh-pages Mar 11, 2015
@dgeb dgeb deleted the consistent-linkage branch March 11, 2015 12:22
@kjwierenga
Copy link
Contributor

:+1 This is indeed more consistent and gets rid of the ugly 'data' member in resource relationsships.

Op 11 mrt. 2015, om 11:48 heeft Dan Gebhardt notifications@github.com het volgende geschreven:

Merged #447 #447.


Reply to this email directly or view it on GitHub #447 (comment).

@ethanresnick
Copy link
Member

+1 on this too!

@hhware
Copy link
Contributor

hhware commented Mar 13, 2015

@dgeb The only time the word "heterogeneous" is mentioned in the spec is a non-normative note. I think it would be useful to provide at least some examples for it, to make it clearer why the resource type needs to be specified twice, in the URL / linkage name and inside the linkage itself. E.g., examples could be provided for creating and updating heterogeneous relationships. Would there be any intetrest in such examples, or they were omitted intentionally?

pmccarren added a commit to dronemill/laravel-jsonapi that referenced this pull request Apr 29, 2015
Ref: json-api/json-api#447

Seems like this PR (linkedRenaming) is an appropriate place to
include this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants