There is one small detail that I have been unable to unify in my head. In some
(many) cases, my head is to blame for this inability, but every once in a while
something is actually a tad off. I add this disclaimer so that everyone feels
totally free in telling me I'm crazy when they reach the end. Of course this
can be true no matter the outcome of this note.
Ion Object and HREF
Let's start with the Ion object. An Ion object by definition has a meta
member. You can add an href member as an "IRI location of the resource" (as
defined in section 6.1).
{
"meta": { "href": "https://example.io/users/1" },
"firstName": "Bob",
"lastName": "Smith",
"birthDate": "1980-01-23"
}
For one, is there any implied link relation here, such as self? Second, if I
were to add a self link relation here, would this link relation be from
the current resource?
As per the spec, it appears that an Ion object with an href is also an Ion
link. And here, the rels for the Ion link are related from itself to another
resource.
Ion Link
Now let's check out an Ion link.
{
"meta": { "href": "http://example.io/foo" },
"user": {
"meta": { "href": "https://example.io/users/1", "rels": ["user"] },
"firstName": "Bob",
"lastName": "Smith",
"birthDate": "1980-01-23"
}
}
I have added an explicit link relation of user here. But for the user link,
the link relation is from the root Ion object to the Ion link. This is a
different pattern than with the first example.
Ion Collections
Another example is how the collection link relation is used. It is a slightly
different than the previous two examples. To recap, the first link relation
appears to relate from itself to another resource. The second appears to relate
from the parent object to the link.
With an Ion collection, the collection relation determines the nature of the
object itself. It is not necessarily a link from itself to a resource or some
self or canonical link. It is rather defines how the object should be
handled, which is slightly different than a normal Ion object.
Why does this even matter, Stephen?
Good question! Hopefully I can put some value to my ramblings.
First, if a link relation acts differently depending on if it's nested or not,
then you can run into some strange situations where you nest an existing
resource with some incorrect link relations.
Take this for example:
{
"meta": { "href": "https://example.io/users/1", "rels": ["self"] },
"firstName": "Bob",
"lastName": "Smith",
"birthDate": "1980-01-23"
}
And embed it in some other object, as shown here:
{
"meta": { "href": "http://example.io/foo" },
"user": {
"meta": { "href": "https://example.io/users/1", "rels": ["self"] },
"firstName": "Bob",
"lastName": "Smith",
"birthDate": "1980-01-23"
}
}
Here you see the nature of link relation changes. I hope that makes sense :)
The collection link relation is another one that has additional meaning. When a
Ion collection is embedded into another Ion object, the rels defines both the
relation and the nature of the collection itself. This may also not be an
issue, but I bring this one up mostly to show the ways that rels works
depending on the context.
Final Observation
As a final note, to think out loud, it is almost as if an Ion object that is
the root object should not have an href, and should rather use a self link
relation (or related relation).
I am not sure I have any recommendation for the Ion collection and what to do
about the rels there. This may be necessary thing. My point is that, in the
case where the Ion collection is the root object, the link relation is used in
a way that does not fit with how Ion links work.
There is one small detail that I have been unable to unify in my head. In some
(many) cases, my head is to blame for this inability, but every once in a while
something is actually a tad off. I add this disclaimer so that everyone feels
totally free in telling me I'm crazy when they reach the end. Of course this
can be true no matter the outcome of this note.
Ion Object and HREF
Let's start with the Ion object. An Ion object by definition has a
metamember. You can add an
hrefmember as an "IRI location of the resource" (asdefined in section 6.1).
{ "meta": { "href": "https://example.io/users/1" }, "firstName": "Bob", "lastName": "Smith", "birthDate": "1980-01-23" }For one, is there any implied link relation here, such as
self? Second, if Iwere to add a
selflink relation here, would this link relation be fromthe current resource?
As per the spec, it appears that an Ion object with an
hrefis also an Ionlink. And here, the
relsfor the Ion link are related from itself to anotherresource.
Ion Link
Now let's check out an Ion link.
{ "meta": { "href": "http://example.io/foo" }, "user": { "meta": { "href": "https://example.io/users/1", "rels": ["user"] }, "firstName": "Bob", "lastName": "Smith", "birthDate": "1980-01-23" } }I have added an explicit link relation of
userhere. But for theuserlink,the link relation is from the root Ion object to the Ion link. This is a
different pattern than with the first example.
Ion Collections
Another example is how the collection link relation is used. It is a slightly
different than the previous two examples. To recap, the first link relation
appears to relate from itself to another resource. The second appears to relate
from the parent object to the link.
With an Ion collection, the
collectionrelation determines the nature of theobject itself. It is not necessarily a link from itself to a resource or some
selfor canonical link. It is rather defines how the object should behandled, which is slightly different than a normal Ion object.
Why does this even matter, Stephen?
Good question! Hopefully I can put some value to my ramblings.
First, if a link relation acts differently depending on if it's nested or not,
then you can run into some strange situations where you nest an existing
resource with some incorrect link relations.
Take this for example:
{ "meta": { "href": "https://example.io/users/1", "rels": ["self"] }, "firstName": "Bob", "lastName": "Smith", "birthDate": "1980-01-23" }And embed it in some other object, as shown here:
{ "meta": { "href": "http://example.io/foo" }, "user": { "meta": { "href": "https://example.io/users/1", "rels": ["self"] }, "firstName": "Bob", "lastName": "Smith", "birthDate": "1980-01-23" } }Here you see the nature of link relation changes. I hope that makes sense :)
The collection link relation is another one that has additional meaning. When a
Ion collection is embedded into another Ion object, the
relsdefines both therelation and the nature of the collection itself. This may also not be an
issue, but I bring this one up mostly to show the ways that
relsworksdepending on the context.
Final Observation
As a final note, to think out loud, it is almost as if an Ion object that is
the root object should not have an
href, and should rather use aselflinkrelation (or related relation).
I am not sure I have any recommendation for the Ion collection and what to do
about the
relsthere. This may be necessary thing. My point is that, in thecase where the Ion collection is the root object, the link relation is used in
a way that does not fit with how Ion links work.