ruby on rails - What REST urls should be used for accessing data from a many-2-many table -


what should syntax of rest calls manipulating (e.g. insert/update/delete) many-2-many table mentioned below rails app.

create table foos (id integer(11), name varchar(255)) create table bars (id integer(11), name varchar(255)) create table foo_bars (foo_id integer(11), bar_id integer(11) foo_id fk foos(id) bar_id fk bars(id) 

should use like?

post /foo/:fooid/bar (to create fooid, barid) put /foo/:fooid/bar/:barid (to update fooid, barid) delete /foo/:fooid/bar/:barid (to delete foo_id, bar_id combination) 

i consider using third endpoint, maybe named checkouts, represent book checked out user, foo-bars table. think it's advisable because relationship has other information associated besides user , book ids. instance, when book due back? can use endpoint track historical information historical activity of book or user. i'm using boolean example purposes, date more appropriate.

// check out books library post /checkouts { "userid":25, "bookids": [ 12, 45, 341 ] }  // renew checkout month put /checkouts  {     "user": "/users/25",     "book": "/books/12",     "dueback": 1438612187,     "returned": false,     ... }  // books checked out bob /checkouts?userid=25&returned=false {     "checkouts" : [ {         "user": "/users/25",         "book": "/books/12",         "dueback": 1438612187,         "returned": false,         ...     },     ...     ] }  // find checkout history of war , peace /checkouts?bookid=12 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -