But extending on this we are creating s specific ingredient resource to re-use.
And we want to add quantity of the ingredient to the recipe, something like:
The ingredients collection within the recipe is not a resource as on it’s own it does not exist.
Technically in the datastore there will be something like recipe_ingredient but not in the resource model.
How would this look like with jsonapi?
Basically I want to have a relationship for each recipe ingredient to an actual ingredient resource.
It’s quite interesting discussion you linked with various opinions.
With my case I just wanted represent a simple example as actually my model is a little bit more complicated
That’s why using "meta" is not an option.
So it probably best to introduce a fabricated resource.
In the example below a use id’s 1, 2 but it probably would be better to use some opaque id here.
Note that I’m also not adding self links to the ingredients resources as I have no resource endpoint for them.
Looking at the spec this is not required. So basically this ingredients resources can only be retrieved as part of the recipes resource, but not on itself, although that feels a little bit weird to be honest.
I’m not gonna lie, this is pretty novel and interesting. Based on my knowledge of the spec, I have to agree this is valid.
I can see some interesting and unintended side effects of this, but I can’t even suggest this is against the intent of the spec.
My feedback, would be to remove the attributes, as they are extraneous, add a sortOrder field if ordering is significant. What is clear is using attribute and include is against the spec.
I’d suggest as a convention for resources using this method to not support the include and possibly even field parameters, as it should render the ingredients unreachable.