Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Regarding your OneToMany relation How to model parent child entities via RESTHow to model parent child entities via REST might help you.

The association with its parent is an attribute of the child resource so the OneToMany relation should be managed on the many side.

PUT /rest/bars/1/foos/2 { # Foo json object } 

Is OK if your foos are only possible in connection with a bar but if they can also exist without a bar you should use a dedicated foo resource not subordinate to the bar resource. Think aggregation or composition.

And if I only want to delete association between Bar(id=1) and Foo(id=2)

DELETE /rest/bars/1/foos/2

I would not use this approach instead update the foo with id=2 to not be associated with bar 1 anymore. A DELETE /rest/bars/1/foos/2 should delete the full foo resource instead of only the association in my opinion.

Regarding ManyToMany relations you'll need a third resource to manipulate the join table directly. To simplify this a little bit this resource will only need the POST and DELETE actions defined. POST to add a new associated pair: to ids, one for bar and one for foo. DELETE to remove such a pair.

Regarding your OneToMany relation How to model parent child entities via REST might help you.

The association with its parent is an attribute of the child resource so the OneToMany relation should be managed on the many side.

PUT /rest/bars/1/foos/2 { # Foo json object } 

Is OK if your foos are only possible in connection with a bar but if they can also exist without a bar you should use a dedicated foo resource not subordinate to the bar resource. Think aggregation or composition.

And if I only want to delete association between Bar(id=1) and Foo(id=2)

DELETE /rest/bars/1/foos/2

I would not use this approach instead update the foo with id=2 to not be associated with bar 1 anymore. A DELETE /rest/bars/1/foos/2 should delete the full foo resource instead of only the association in my opinion.

Regarding ManyToMany relations you'll need a third resource to manipulate the join table directly. To simplify this a little bit this resource will only need the POST and DELETE actions defined. POST to add a new associated pair: to ids, one for bar and one for foo. DELETE to remove such a pair.

Regarding your OneToMany relation How to model parent child entities via REST might help you.

The association with its parent is an attribute of the child resource so the OneToMany relation should be managed on the many side.

PUT /rest/bars/1/foos/2 { # Foo json object } 

Is OK if your foos are only possible in connection with a bar but if they can also exist without a bar you should use a dedicated foo resource not subordinate to the bar resource. Think aggregation or composition.

And if I only want to delete association between Bar(id=1) and Foo(id=2)

DELETE /rest/bars/1/foos/2

I would not use this approach instead update the foo with id=2 to not be associated with bar 1 anymore. A DELETE /rest/bars/1/foos/2 should delete the full foo resource instead of only the association in my opinion.

Regarding ManyToMany relations you'll need a third resource to manipulate the join table directly. To simplify this a little bit this resource will only need the POST and DELETE actions defined. POST to add a new associated pair: to ids, one for bar and one for foo. DELETE to remove such a pair.

Source Link

Regarding your OneToMany relation How to model parent child entities via REST might help you.

The association with its parent is an attribute of the child resource so the OneToMany relation should be managed on the many side.

PUT /rest/bars/1/foos/2 { # Foo json object } 

Is OK if your foos are only possible in connection with a bar but if they can also exist without a bar you should use a dedicated foo resource not subordinate to the bar resource. Think aggregation or composition.

And if I only want to delete association between Bar(id=1) and Foo(id=2)

DELETE /rest/bars/1/foos/2

I would not use this approach instead update the foo with id=2 to not be associated with bar 1 anymore. A DELETE /rest/bars/1/foos/2 should delete the full foo resource instead of only the association in my opinion.

Regarding ManyToMany relations you'll need a third resource to manipulate the join table directly. To simplify this a little bit this resource will only need the POST and DELETE actions defined. POST to add a new associated pair: to ids, one for bar and one for foo. DELETE to remove such a pair.