Hello,
I have tried to google and search in this disccuss board but with no luck. It’s possible that following question is too abstract and arose because i missed something in jsonapi.org specification or here in search results.
The question is about how to handle resourses which are related to each other and also how i should ( by convention ) access these resourses and when i should use relationship between them and when i should access them as seperate resourses.
There’s concrete example. Let’s assume that we have resourses that are related to each other: Countries, States and Cities. So, countries has many states, states has many cities and i’m going implement something like this: http://www.91weblessons.com/demo/codeigniterCountryStateCityDropDown/index.php
The first idea is to have three seperate endpoints:
- /v1/module/countries
- /v1/module/states
- /v1/module/cities
There’s a workflow:
Retrieved all countries from countries endpoint and have chosen “Vietnam”.
Now i need to retrieve all Vietnam states.
When i got all states in some way i have chosen An Giang state and now i need to get all cities for this state.
Should i use here relationship or not and in case i should how it should look like?
There’s some mine thoughts:
- /v1/counties/country:id/relationship/states -
- /v1/states/states:id/relationship/cities
Or should i use just links to original resourses:
- /v1/states?filter[country:id]=country:id
- /v1/cities?filter[state:id]=state:id
If i do understand correctly all these relationships are just links to original resourse just represended in relationship manner. /v1/counties/country:id/relationship/states actualy is link to /v1/states?filter[country:id]=country:id ?
Also i would appreaciate any guidliness related API development.