OK I can GET POST PUT DELETE simple resources (entities) in my RESTful web service
ex.
/rest/foos
/rest/foos/1
/rest/bars
/rest/bars/1
But how to handle adding relationships ex. @OneToMany, @ManyToMany between this relationships using RESTful web service. Suppose I have several Foo entities and several Bar entities how to establish relationships Bar 1 has Foo 3 , etc.
I have such approach to GET this relationships:
GET /rest/bars/1/foos
Above returns collection of foos related with Bar(id=1)
I cosider maybe doing it this way:
POST /rest/bars/1/foos { # Foo json object }
Above will create new Foo object and make association between this new object and Bar(id=1).
PUT /rest/bars/1/foos/2 { # Foo json object }
Above updates Foo(id=2) if there is such association with Bar(id=1) or if there isn't such association and Foo(id=2) exists in Foo table such association will be made.
If I would like to add/update only Foo without association i made sth like below:
POST /rest/foos
PUT /rest/foos/2
If I would like to remove Foo(id=2)
DELETE /rest/foos/2
And if I only want to delete association between Bar(id=1) and Foo(id=2)
DELETE /rest/bars/1/foos/2
What do you think about such approach? And how would you handle this correctly?