I wonder how the following simple situation would be specified using json:api.
We have a person object with a bunch of attributes. One of this attributes is country in which the person is living. In the User Interface the attribute country is rendered as a combo-box to be able to choose from a list of countries.
Would it be specified like below, assuming the current person would live in Switzerland?
In order to fill the combobox with the list of countries it would be nice if somewhere the linke â/countriesâ would be specified within the document? How can this be achieved?
That looks about right. As for âsimplerâ, there are some fields that youâve included that arenât strictly required, such as links.
The complete list of countries would typically be fetched in a separate request to /countries. If you really want them included in the same request, youâd need to reference them from the primary resource with a relationship such as possible-countries and then list them all in included (itâs pretty hard to recommend this approach though).
Thanks for your answer. As a newcomer with json:api I feel now saver because you confirmed that I understood the concept of the specification.
My idea was not to include the list of countries in the same response. What I like to achieve is to place the link to â/countriesâ somewhere in the response. So that the client knows where to fetch the list of all countries. Otherwise the client needs to know this link. So how would you achieve this?
When included in a resource that represents a member of a collection,
the âcollectionâ link relation identifies a target resource that
represents a collection of which the context resource is a member.
I canât guarantee that JSON API wonât reserve this link for a slightly different purpose in the future, but to me this seems like the most clean solution.