I am not sure what is the best placement of a link to POST a resource. I’ll explain with an example.
I have a shift (name) parent resource (shift in the sense work period) with many shift positions (shift relationship, position relationship, required) which is related to a position (position in the sense job type, e.g. Driver).
I POST a shift resource. I want the response to include a link to the URI to consequently POST a shift position resource. I have the following three possibilities to place the create_shift_positions link:
First
{
"data": {
"id": "100",
"type": "shift",
"attributes": {
"name": "Shift 5"
},
"relationships": {
"shift_positions": {
"data": [],
"links": {
"create_shift_positions": "example.org/shifts/100/shift_positions"**
}
}
},
"links": {
"self": "example.org/shifts/100"
}
}
}
Second
{
"data": {
"id": "100",
"type": "shift",
"attributes": {
"name": "Shift 5"
},
"relationships": {
"shift_positions": {
"data": []
}
},
"links": {
"self": "example.org/shifts/100",
"create_shift_positions": "example.org/shifts/100/shift_positions"
}
}
}
Third
{
"data": {
"id": "100",
"type": "shift",
"attributes": {
"name": "Shift 5"
},
"relationships": {
"shift_positions": {
"data": []
}
},
"links": {
"self": "example.org/shifts/100",
}
},
"links": {
"create_shift_positions": "example.org/shifts/100/shift_positions"
}
}
What would be the best placement of such a link? Does the specification favor a particular approach? What would be the benefits of using one over the others?