Composite ID inside the resource object

@brainwipe first of all thank you for the suggestion to model the problem with relations.
However, this is not an answer to the original problem (the question wasn’t properly defined, sorry)

Let me clarify it:

  • Some entities have a natural unique key (https://en.wikipedia.org/wiki/Natural_key) coming from business
    Example: consider Product that is defined by EAN (European Article Number). In this case EAN is used as “id” attribute as it uniquely identifies a product (at least in Europe).

  • Other entities don’t have a unique key that comes from business, but they do have a surrogate unique key (https://en.wikipedia.org/wiki/Surrogate_key) that is generated by db (Using SERIAL type in Postres, for example). In this case its also can be used in “id” attribute.

  • And there are entities that have compound keys and no surrogate keys. The problem is that they don’t fit into string-typed “id” attribute

In your proposal above there is an assumption that both entities “a” and “b” have scalar keys (either natural or surrogate).

Please consider this somewhat contrived example:
We are modeling and inventory microservice that is capable of saving quantities of products per merchant. Some other microservices are responsible for Merchant and Product entities; So there is a Quantity entity our Inventory microservice is responsible for.

And its not clear how to expose Quantity using JSON-API compliant API because its not clear what to put in its “id” attribute.