mikekelly / hal_specification

HAL Specification
http://stateless.co/hal_specification.html
618 stars 58 forks source link

Let `_embedded` reference other items from the representation. #42

Open spaceone opened 2 years ago

spaceone commented 2 years ago

It would be nice if embedded resources could point to a location inside the current representation where the data lie.

Example:

instead of:

{
    "results": 2,
    "_embedded": {
        "foo:objects": {
            {"foo": "bar", "_links": {}},
            {"bar": "baz", "_links": {}},
        }  
    },
    "_links": {
        "curies": {
            "name": "foo",
            "href": "bar"
        }
    }
}

I would like to write:

{
    "results": 2,
    "objects": [
        {"foo": "bar", "_links": {}},
        {"bar": "baz", "_links": {}},
    ],
    "_embedded": {
        "foo:objects": $LINK_TO('/objects')$
    },
    "_links": {
        "curies": {
            "name": "foo",
            "href": "bar"
        }
    }
}

where $LINK_TO('/objects')$ should be some non-breaking idea. Maybe something like:

"_links": {
    "hal:embedded-ref": "/objects"
}

which would be a xpath / jsonpath expression. :-( this would be a dependency on another library. TODO / RFC: find a better idea

For me it would be enough to reference a top-level item.