Child crud vs Child associaton

64 views
Skip to first unread message

mike_s

unread,
Oct 7, 2012, 2:15:14 PM10/7/12
to api-...@googlegroups.com
Hi all,

a design question on best handling for Link/unlink of two resources vs removal of a child Item from a Parent list. For example difference between adding removing from a Group  vs add/remove of a child record in former case, there is no child delete - in the latter (the child record would be deleted)


1)manage  CRUD for dependent Child record :      /parents/{id}/children/27  GET

which is preferred?

a) /parents/{id}/children/27 DELETE      
b)  /children/27 DELETE    //  I prefer this one as i want to avoid a runaway url:  /parents/{id}/children{id}/toys/{}

2) Link/unlink   (entity to a group (many_2_many)     /group/{id}/children/27  GET

a) /group/{id}/children/27        PUT  or POST?
b)  /group/{id}/associate?child=27       POST?
c)  /group/{id}/associate/27 PUT ?

let me know your thoughts on the best practice for the linking case...

Cheers,
Mike

Kristof Kotai

unread,
Oct 7, 2012, 3:44:50 PM10/7/12
to api-...@googlegroups.com
Hi,
if you are using this pattern:

/resource1/:id1/resource2/:id2

for referring to associations between resources, then you are doing so because you need some kind of context for "resource2" to be identified.
If that is the case, then all the CRUD operations should be using that pattern. Namely:

GET    /resource1/:id1/resource2/:id2     (get a specific resource2 element)
PUT    /resource1/:id1/resource2/:id2     (modify)
DELETE /resource1/:id1/resource2/:id2     (delete)
POST   /resource1/:id1/resource2          (create a resource2 element in the resource1 context. And 
                                           should usually be only accessible through the same context)

Hope it helps

mike_s

unread,
Oct 7, 2012, 6:41:59 PM10/7/12
to api-...@googlegroups.com
thanks  Kristof -  the removal of single child association from Collection using DELETE (below ) was the missing piece I needed.  This will work for large datasets as scope is only 1 record to be "unlinked".  Cheers!


 DELETE /resource1/:id1/resource2/:id2     (delete)



Reply all
Reply to author
Forward
0 new messages