You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I fully agree that this is a topic, which we should address explicitly. The current specification only addressed it implicitly and the outcome is not what I would expect.
Let's see what we have in latest v1.1:
A resource can be created by sending a POST request to a URL that represents a collection of resources.
A “related resource link” provides access to resource objects linked in a relationship. When fetched, the related resource object(s) are returned as the response’s primary data.
For example, an article’s comments relationship could specify a link that returns a collection of comment resource objects when retrieved through a GET request.
A relationship may either represent a single resource, or multiple resources depending if it is a to-one or to-many relationship. Both kinds of relationships are mentioned explicitly for resource linkage data:
Resource linkage MUST be represented as one of the following:
null for empty to-one relationships.
an empty array ([]) for empty to-many relationships.
a single resource identifier object for non-empty to-one relationships.
an array of resource identifier objects for non-empty to-many relationships.
Putting all that together it seems that a client can use a related resource link to create a resource if that related resource link represents a to-many relationship (and if the server supports it). However creating of resources using a related resource link is not possible, if the related resource link represents a to-one relationship as that one does not represent a collection.
It feels very off to me that resource creation is possible in one case (to-many) but not in the other (to-one) for the same link type. I think the specification should either support it for both - or for none of them.
If explicit support for creation of resource using a related resource link is added to the specification, it should also standardize if the server should add the new resource to that relationship by default.
Using a related resource link to create resources, which are added automatically to a relationship with another resource, seems to be a highly requested feature. So I would tend towards adding explicit support for it. If adding to the relationship is not a must but a should we could also avoid breaking backward compatibility.
Activity
jelhan commentedon Jan 29, 2022
I fully agree that this is a topic, which we should address explicitly. The current specification only addressed it implicitly and the outcome is not what I would expect.
Let's see what we have in latest v1.1:
A relationship may either represent a single resource, or multiple resources depending if it is a
to-oneorto-manyrelationship. Both kinds of relationships are mentioned explicitly for resource linkage data:Putting all that together it seems that a client can use a related resource link to create a resource if that related resource link represents a to-many relationship (and if the server supports it). However creating of resources using a related resource link is not possible, if the related resource link represents a to-one relationship as that one does not represent a collection.
It feels very off to me that resource creation is possible in one case (
to-many) but not in the other (to-one) for the same link type. I think the specification should either support it for both - or for none of them.If explicit support for creation of resource using a related resource link is added to the specification, it should also standardize if the server should add the new resource to that relationship by default.
Using a related resource link to create resources, which are added automatically to a relationship with another resource, seems to be a highly requested feature. So I would tend towards adding explicit support for it. If adding to the relationship is not a must but a should we could also avoid breaking backward compatibility.
Merge pull request json-api#962 from Arafatk/patch-4