In this question I’m referring specifically to resource objects:
http://jsonapi.org/format/#document-resource-objects.
How do I decide whether to use a links
or relationships
?
I understand that relationships
provides features that links
does not, such as changing the author of an article by issuing a DELETE/POST to the article’s author relationship.
In my use-case I do not need to explicitly reference or alter the relationship, I only need to provide the link to the related resource, but I’m curious if I should use the relationships
object anyway.
Example:
I have a typical json:api resource, and I want to provide a POST only sub-resource.
resource: GET|POST /projects
sub-resource: POST /projects/1/workflow-transition
Note that I’ve rejected the approach of using PUT /projects to make the data changes involved in the workflow transition, because it would require the client app to understand too much server-side business logic.
In Relation Link Usage @ethanresnick says
"[The related
link is] designed primarily for GET, though I think the spec would also allow a POST to it."
So at least it may be allowed to use relationships
like so:
{
"type": "projects",
"id": "1",
"attributes": {...},
"relationships": {
"workflow-transition": {
"links": {
// client issues a POST to this URL
"related": "/projects/1/workflow-transition"
}
}
}
}
However since I don’t really need to model the relationship between a project
and its workflow-transition
, it seems simpler to use a links
object instead.
{
"type": "projects",
"id": "1",
"attributes": {...},
"links": {
"workflow-transition": "/projects/1/workflow-transition"
}
}
Are there reasons to use one or the other approach?