Suppose Person
has a Car
. Car
is a separate resource with its own URI. For the sake of this example, assume a person can only have one car.
We want to include the Person's Car in the response when requesting a person via /person/{id}
, but we don't want to include the entire Car
resource with all of its properties which may be a complicated nested structure. We only want to include a few of the main properties, such as Color, Make, and Model, along with a link to the full Car
resource.
Is it normal to have a different representation of
Car
that only exists as a child property ofPerson
?Car
may also have even more simplified representations as a child of other resources as well, depending on what properties it makes sense to expose based on the parent resource.Since I'm not including an "official" representation of the
Car
resource (one that has its own URI) insidePerson
, do I include the link to the fullCar
resource inside the childCar
property onPerson
or do I put the link in the list of links on the parent resourcePerson
?
Include link on the parent resource Person
:
{
"Person": {
"Name": "John Smith",
"Age": 25,
"Car": {
"Make": "Toyota",
"Model": "Camry",
"Year": 2012
},
"Links": [
{
"rel": "car",
"href": "/person/{id}/car"
},
{
"rel": "some-other-resource",
"href": "/person/{id}/some-other-resource"
}
]
}
}
Or include the Car
link in the child property Car
:
{
"Person": {
"Name": "John Smith",
"Age": 25,
"Car": {
"Make": "Toyota",
"Model": "Camry",
"Year": 2012,
"Links": [
{
"rel": "self",
"href": "/person/{id}/car"
}
]
},
"Links": [
{
"rel": "some-other-resource",
"href": "/person/{id}/some-other-resource"
}
]
}
}
do I include the link to the full Car resource
-- If you want the consuming application to have the ability to navigate to the full Car resource.Is it normal to have a different representation of Car that only exists as a child property of Person?
-- I would imagine that the way you represent Person in this context is entirely up to you.Person
resource. There seems to be a reading comprehension issue here.