restsubscription

Is it normal to create two unrelated (different) resources in one request?


When a user offers friendship to another user, he automatically subscribes to him. How to implement this in REST API? Two different entities (aggregates) are created in one request: Friendship (with OFFERED status) and Subscription, but the endpoint is called /friendships. Is it normal that there is such a side effect as a subscription? Or should I implement it differently? Are there recommendations for such situations?

I want the logic to remain the same: automatic subscription occurs when a friendship is offered. Not otherwise.


Solution

  • In my opinion, adding a subscription when adding a friendship is your own application logic (which can be changed in future based on how yours users like it). It has nothing to do with the endpoint and /friendships is perfectly fine.