spring-projects / spring-projects/spring-hateoas

HAL: the rel for an embedded collection should be singular (the item-resource-rel)

Open
#339 4 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since May 21, 2015.

process: waiting for feedback unlikely
Dominant language
Java
Stars
1.1k
Forks
476
PR merge metrics
No merged PRs in 30d

Description

I think the implementation of the HalEmbeddedBuilder is outdated/wrong in selecting a plural collection link-rel when embedding multiple resources. In my understanding of the spec, linking to items in a collection resource (e.g. "/items") should be regarded as multiple links with the rel "item" (like multiple <a href="/items/1" rel="item">), serialized into an array. The rel should remain "item".

The collection-link-rel "items" should only be used if actually linking to the collection resource (i.e. "/items").

Otherwise it becomes impossible to distinguish between the link to a collection resource and a link to a single resource.

For example:

/items

{
  "_links": {
    "self": {href: "/items"}
  },
  "_embedded": {
    "item": [
      {
        "_links": {
          "self": {href: "/items/1"}
        }
      }
    ]
  }
}

/items/1

{
  "_links": {
    "self": {href: "/items/1"}
    "items": {href: "/items"}
  },
  "id": "1"
}

The targets for "items" and "item" are distinctly different, so they should have distinct rels.

The HAL spec itself is confusing in that regard - the published spec still holds an example using the orders-rel, but it has been corrected on Mike Kelly's website where it now shows the ea:order-rel.
It has also been discussed on the mailing list.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.