When Iām facing situation like that Iām always starting to think that it would be better to split everything to relationships because it will be easier to extend app functionality later, itās cheaper to find related resources by IDs than by string values, but on the other side Iām starting to think that Iām making very complicated API which will be hard to work with.
For example with wage another one approach was to split complex attribute to many relationships.
GET /jobs/1?include=wage.currency,wage.system,wage.unit
{
"data": {
"type": "job",
"id": "1",
"relationships": {
"wage": {
"data": {
"type": "wage",
"id": "2"
}
}
}
},
"included": [
{
"type": "wage",
"id": "2",
"attributes": {
"rate": "300"
},
"relationships": {
"currency": {
"data": {
"type": "currency",
"id": "31"
},
"system": {
"data": {
"type": "wage-system",
"id": "4"
}
},
"unit": {
"data": {
"type": "wage-unit",
"id": "5"
}
}
}
}
},
{
"type": "currency",
"id": "31",
"attributes": {
"code": "USD"
}
},
{
"type": "wage-system",
"id": "4",
"attributes": {
"name": "time-based"
}
},
{
"type": "wage-unit",
"id": "5",
"attributes": {
"name": "hourly"
},
"relationships": {
"system": {
"data": {
"type": "wage-system",
"id": "4"
}
}
}
}
]
}
But wouldnāt it be harder for developers to work with it?
With complex attribute it will look like this:
GET /jobs/1
{
"data": {
"type": "job",
"id": "1",
"attributes": {
"wage": {
"system": "time-based",
"unit": "hourly",
"currency_code": "USD",
"rate": 300
}
}
}
}
What questions should developer to ask to clearly understand is it complex attribute or relationships?
Sorry for that off-topic question, but itās rasing every time Iām trying to find the right word not so common as type: āMaybe itās better to create one more relationship with itās own type instead of introducing complex attribute?ā.