java - How to deal with aggregation and composition in RESTful web service -
i have created following entities, book
, chapter
, feedback
. book
have many chapter
entities, , have many feedback
entities. since no chapter
entities live them self part of book
composition. same applies feedback
entitiy.
my question whether objects part of composition should have own uris in restful system? such as:
/books/1/chapters (with post, delete, put operations) /books/1/feedback (with post, delete, put operations)
or should threated this:
/books/1 (with post, delete, put operations on book)
the last uri mean users of api have add feedback array of book , update whole book entity.
and make sense call relationship between books , chapters "composition + aggregation" since chapters doesn't belong other object , life cycle dependent of book?
my question whether objects part of composition should have own uris in restful system
yes, definitely. makes significantly easier access , manage specific parts of entity representation when parts independently addressable. rather requiring clients retrieve whole representation each time update small portions of it, can focus on 1 part needs modified. simplifies access control, endpoints may available particular callers not others.
the 1 constraint kept when defining sub-resource uri's defined within scope of parent resource (as showing in example).
and make sense call relationship between books , chapters "composition + aggregation" since chapters doesn't belong other object , life cycle dependent of book
it makes sense refer relationship composition. aggregation mean sub-resource (chapter) exist outside scope of parent (book), in case cannot. example of aggregation address, associated person, or organization.
Comments
Post a Comment