Heracles.ts icon indicating copy to clipboard operation
Heracles.ts copied to clipboard

Should we keep using the "hypermedia interface" or switch to something else?

Open lanthaler opened this issue 8 years ago • 1 comments

This was raised in PR #11:

            expect(this.result.hypermedia).toEqual([
                {
                    iri: "http://temp.uri/api/events",
                    isA: [hydra.Collection],
                    totalItems: 1,
                    members: [
                        {
                            iri: "http://temp.uri/api/events/1",
                            isA: [],
                            "http://schema.org/endDate": "2017-04-19",
                            "http://schema.org/eventDescription": "Some event 1",
                            "http://schema.org/eventName": "Event 1",
                            "http://schema.org/startDate": "2017-04-19"
                        }
                    ]
                }, {
                    iri: "http://temp.uri/api/events/1",
                    isA: [],
                    "http://schema.org/endDate": "2017-04-19",
                    "http://schema.org/eventDescription": "Some event 1",
                    "http://schema.org/eventName": "Event 1",
                    "http://schema.org/startDate": "2017-04-19"
                }, {
                    iri: 'some:named.graph',
                    isA: []
                }
            ]);
        });

I made the following comment:

I think this shows the leaky nature of this interface quite clearly. It returns a more or less random set of data. I'd expect to be able to get a list of links to related resources and a list of operations that I then can invoke.

Something like

links = this.result.getLinks();
--> returns an array of Link instances which have the property, the target 
    (and perhaps a few additional properties describing the target)
links[0].getProperty() --> examplevocab:events
links[0].getTarget() --> /api/events
...

This link could then simply be passed to the client this.client.getResource(links[0]) or, perhaps more intuitive, links[0].retrieveTarget(this.client)

lanthaler avatar Sep 17 '17 18:09 lanthaler

Raw resource would also be a bag of random data. Having that single hypermedia property is a good place to expand with more specialized accessors. Last #11 introduced hypermedia.members that actually filters this bag to those resources with hydra:member relation, leaving original resource untouched. You can imagine that this bag could come with links or getLink accessors having all hypermedia in one place.

alien-mcl avatar Sep 18 '17 18:09 alien-mcl