mikekelly / hal_specification

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

JSON example and hypertext cache pattern #16

Open pnsantos opened 10 years ago

pnsantos commented 10 years ago

Hi Mike,

I think there was a thread in hal-discuss about this but shouldn't the example in the main page have an ea:order within the links section? like so:

{
    "_links": {
        "self": { "href": "/orders" },
        "curies": [{ "name": "ea", "href": "http://example.com/docs/rels/{rel}", "templated": true }],
        "next": { "href": "/orders?page=2" },
        "ea:find": {
            "href": "/orders{?id}",
            "templated": true
        },
        "ea:admin": [{
            "href": "/admins/2",
            "title": "Fred"
        }, {
            "href": "/admins/5",
            "title": "Kate"
        }],
        "ea:order": [
           { "href": "/orders/123" },
           { "href": "/orders/124" }
        ]
    },
    "currentlyProcessing": 14,
    "shippedToday": 20,
    "_embedded": {
        "ea:order": [{
            "_links": {
                "self": { "href": "/orders/123" },
                "ea:basket": { "href": "/baskets/98712" },
                "ea:customer": { "href": "/customers/7809" }
            },
            "total": 30.00,
            "currency": "USD",
            "status": "shipped"
        }, {
            "_links": {
                "self": { "href": "/orders/124" },
                "ea:basket": { "href": "/baskets/97213" },
                "ea:customer": { "href": "/customers/12369" }
            },
            "total": 20.00,
            "currency": "USD",
            "status": "processing"
        }]
    }
}

According to the section about Hypertext cache pattern:

To activate this client behaviour for a given link, servers SHOULD add an embedded resource into the representation with the same relation.

Servers SHOULD NOT entirely "swap out" a link for an embedded resource (or vice versa) because client support for this technique is OPTIONAL.

This would imply that to have an embedded resource ea:order there SHOULD be a link ea:order which in this case would be an array of links, where each link points to a resource (which is what is being embedded).

If you agree I can make a pull request.

jkobus commented 8 years ago

I'm also interested in answer to this question. Anyone?

Update: https://groups.google.com/d/msg/hal-discuss/O_U1x6Wdz-g/fBtP_oZzLkUJ