Skip to content

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

Open
@meyertee

Description

@meyertee

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions