What is the best way to design a many to many relation with hateoas
?
I have a bidirectional relation between two classes, defined with a Set
.
My problems are the POST
/ PUT
methods for binding one resource to the other.
(Making a Relation)
Example:
class A {
int id;
String nameOfA = "A";
Set<B> set;
}
class B {
int id;
String nameOfB = "B";
Set<A> set;
}
First way: resource uris could be
/A/{aid}/B/{bid}
/B/{bid}/A/{aid}
For adding a relation between A
with id 1 and B
with id 2 I would make a POST
on: /A/1/B/2
or /B/2/A/1
.
Second way:
For adding a relation between A
with id 1 and B
with id 2 POST
on /A/1/B
with a "B-object" as content:
{id:2,nameOfB:"B"}
Which is the better way or are there even better solutions? Thanks for help :)