Relationship Collection Name


#1

Can the name of a relationship be different than the name of the resource? For example:

GET AnyResource Collection

{
“data”: [{
“type”: “AnyResource”,
“id”: “1.0”,
“attributes”: {
“version”: “1.0”
},
“relationships”: {
“FilterResources”: {
“links”: {
“related”: “/any/1.0/filters”
}
}
},
“links”: {
“self””: " /any/1.0"
}
}, {
“type”: “AnyResource”,
“id”: “2.0”,
“attributes”: {
“version”: “2.0”
},
“relationships”: {
“FilterResources”: {
“links”: {
“related”: “/any/2.0/filters”
}
}
},
“links”: {
“self””: " /any/2.0"
}
}],
“links”: {
“self””: " /any"
}
}

GET FilterResource Collection from AnyResource 1.0

{
“data”: [{
“type”: “FilterResource”,
“id”: “1”,
“attributes”: {
“color”: “FFFFFF”
}
}, {
“type”: “FilterResource”,
“id”: “2”,
“attributes”: {
“color”: “000000”
}
}],
“links”: {
“self”: “/any/1.0/filters”
}
}

The name of the relation “FilterResources” does not match the type of the singular resource that is returned in the collection: “FilterResource”. Is this compliant with the API?


#2

Yes, just look at canonical example for json:api on their website: the relation name for the person who wrote an article is “author” but the resource type is Person.