I am strucuring our rest API resources and came accross an interesting dilemma. Here is the scenario and I am going to use a car analogy
/cars/1/
{
"id": 1,
"make": "Toyota",
"year_build": 2015
...
}
/cars/models/1/insurances
{
"id": 1,
insurances: [
{
"policy_number": 101,
"company": "Insurance Company 1",
"valid_until": "2015-01-01"
},
{
"policy_number": 102,
"company": "Insurance Company 2",
"valid_until": "2016-01-01"
}
]
...
}
I notice that resources can be reached with both
/cars/1/insurances/102 and /cars/1/insurances?policyid=102, but /cars/1/insurances/102 is more handier if we want to use additional subresources such as /cars/1/insurances/102/agents/....
My question really is do I have to follow the full path of url if each policy has a unique number, for example could i use
/cars/insurances/102
to get this policy instead of
/cars/1/insurances?policyid=102
Would take make a policy a primary resource instead of a car?