hyperresource
hyperresource copied to clipboard
Links following curies href
Hi. I'm trying to use hyperresource to consume the following API from server:
{
"_links" : {
"curies" : [ {
"href" : "http://example.com/docs/{rel}",
"name" : "common",
"templated" : true
} ],
"self" : {
"href" : "http://example.com"
},
"common:version" : [ {
"href" : "/version/{name}",
"templated" : true
} ]
}
The problem is the following
When I do api.get.version[0].url
it returns http://example.com/version
based on self.href
link, which is not what I expected. Since version
link belongs to common
cury, I expected url property to look like http://example.com/docs/version/{some_name_parametr}
I see it uses resource.root
which is passed in Hyperresource constructor.
https://github.com/gamache/hyperresource/blob/master/lib/hyper_resource/link.rb#L73
Probably the case to consider. Regards.
Hello, and thank you for writing! Every report makes HyperResource better.
CURIEs are applied to the link rel, not the link itself. In many existing applications of hypermedia, link rels are referred to by URL -- for instance, with a schema.org address, or with a URL that points to human documentation for the link. These URLs often originate from different hosts than the API. If the API wishes to link to data on other servers, it can do so by specifying a fully-qualified href instead of a relative one.
None of this is in the HyperResource documentation, though, so I don't blame you for being confused. I will leave this issue open until I clarify this in the README.
Thanks again.
-pete
I assumed I could misunderstand some concepts of protocol. Thanks for clarifying.
I have once again taken a look at the problem, thoroughly reading protocol specification. The RFC draft of json+hal gives the following example of CURIE usage:
http://tools.ietf.org/html/draft-kelly-json-hal-06
The CURIE Syntax [W3C.NOTE-curie-20101216] MAY be used for brevity
for these URIs. CURIEs are established within a HAL document via a
set of Link Objects with the relation type "curies" on the root
Resource Object. These links contain a URI Template with the token
'rel', and are named via the "name" property.
{
"_links": {
"self": { "href": "/orders" },
"curies": [{
"name": "acme",
"href": "http://docs.acme.com/relations/{rel}",
"templated": true
}],
"acme:widgets": { "href": "/widgets" }
}
}
The above demonstrates the relation "http://docs.acme.com/relations/
widgets" being abbreviated to "acme:widgets" via CURIE syntax.
And if referring to CURIE w3 specification, it says that
http://www.w3.org/TR/2010/NOTE-curie-20101216/#s_usage
the process of evaluating involves replacing the CURIE with a concatenation of the value represented by the prefix and the part after the colon (the reference)
In the above example, the value represented by the prefix is http://docs.acme.com/relations/{rel}
and the part after the column is widgets
, that evaluates to href /widgets
, concatenation of which yields http://docs.acme.com/relations/widgets
Regards