Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Best REST practises for adding and removing an element as opposed to deletion, and creation

Received: by 10.66.75.164 with SMTP id d4mr207159paw.10.1349234500926;
        Tue, 02 Oct 2012 20:21:40 -0700 (PDT)
X-BeenThere: api-craft@googlegroups.com
Received: by 10.68.197.163 with SMTP id iv3ls4626513pbc.9.gmail; Tue, 02 Oct
 2012 20:21:38 -0700 (PDT)
Received: by 10.68.242.37 with SMTP id wn5mr937445pbc.4.1349234498168;
        Tue, 02 Oct 2012 20:21:38 -0700 (PDT)
Date: Tue, 2 Oct 2012 20:21:37 -0700 (PDT)
From: Aaron Caswell <caswell.aa...@gmail.com>
To: api-craft@googlegroups.com
Message-Id: <71339652-66d8-4c09-a8e6-4b82d2e04f90@googlegroups.com>
Subject: Best REST practises for adding and removing an element as opposed
 to deletion, and creation
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_961_4062540.1349234497795"

------=_Part_961_4062540.1349234497795
Content-Type: multipart/alternative; 
	boundary="----=_Part_962_29403002.1349234497795"

------=_Part_962_29403002.1349234497795
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hi Everybody,

I am sure this must have been answered well somewhere before, but I can't 
seem to find an answer that satisfies me...
I have a collection of 'fights', and a collection of 'fighters'. I want to 
be able to add and remove fighter to a fight restfully. Hence my resources 
and URI's are like so:
/fights/ -> all the fights that exist
/fights/{fightId} -> gives me fight fightId
The usual CRUD ops work on these resources as expected, like POST to 
/fights/ generates a new fight, etc.

Similarly,
/fighters/
/fighters/{fighterId}
does the same for fighters.

Now, it makes sense to me that a GET on the following should list all 
fighters scheduled for fightId:
/fights/{fightId}/fighters/
But what would be the advised way to add and remove fighters to/from a 
fight? To add should I POST to this URI with the id of an already existing 
fighter in the query string? Would I do a DELETE to 
/fights/{fightId}/fighters/{fighterId} to remove that fighter?
Maybe I am being picky, I don't know. My concern is that if I were to 
follow this approach then there is some inconsistency in DELETE's to 
/fighters/{fighterId} vs /fights/{fightId}/fighters/{fighterId}. One 
actually deletes an object from the DB whereas the other deletes an 
association, not the actual object it is talking about. However, the 
different URI's do establish the context of the operations, which maybe 
acceptable.
How rigid should these things be, or should I breakdown and make and add, 
remove verbs hanging off the end like this:
/fight/{fightId}/add?category=fight&id=fighterId
which seems complicated and yucky.

I hope I am clear-ish. Thank you in advance,

Aaron


------=_Part_962_29403002.1349234497795
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<div>Hi Everybody,</div><div><br></div><div>I am sure this must have been a=
nswered well somewhere before, but I can't seem to find an answer that sati=
sfies me...</div><div>I have a collection of 'fights', and a collection of =
'fighters'. I want to be able to add and remove fighter to a fight restfull=
y. Hence my resources and URI's are like so:</div><div style=3D"background-=
color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap:=
 break-word; " class=3D"prettyprint"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #080;" class=3D"styled-by-prettif=
y">/fights/</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> all the figh=
ts that exist<br></span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">/</span><span style=3D"color: #000;" class=3D"styled-by-prettify">fi=
ghts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">/{</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">fightId</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">-&gt;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> gives me fight fightId</span></div></co=
de></div><div>The usual CRUD ops work on these resources as expected, like =
POST to /fights/ generates a new fight, etc.</div><div><br></div><div>Simil=
arly,</div><div style=3D"background-color: rgb(250, 250, 250); border: 1px =
solid rgb(187, 187, 187); word-wrap: break-word; " class=3D"prettyprint"><c=
ode class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">/fighters/</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">/</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">fighters</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">/{</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">fighterId</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">}</span></div></code></div><div>does the same for fighters.<=
/div><div><br></div><div>Now, it makes sense to me that a GET on the follow=
ing should list all fighters scheduled for fightId:</div><div><div style=3D=
"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187)=
; word-wrap: break-word; " class=3D"prettyprint"><code class=3D"prettyprint=
"><div class=3D"subprettyprint"><span style=3D"color: #080;" class=3D"style=
d-by-prettify">/fights/</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">fightId</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>}/</span><span style=3D"color: #000;" class=3D"styled-by-prettify">fighter=
s</span><span style=3D"color: #660;" class=3D"styled-by-prettify">/</span><=
/div></code></div></div><div>But what would be the advised way to add and r=
emove fighters to/from a fight? To add should I POST to this URI with the i=
d of an already existing fighter in the query string? Would I do a DELETE t=
o /fights/{fightId}/fighters/{fighterId} to remove that fighter?</div><div>=
Maybe I am being picky, I don't know. My concern is that if I were to follo=
w this approach then there is some inconsistency in DELETE's to /fighters/{=
fighterId} vs /fights/{fightId}/fighters/{fighterId}. One actually deletes =
an object from the DB whereas the other deletes an association, not the act=
ual object it is talking about. However, the different URI's do establish t=
he context of the operations, which maybe acceptable.</div><div>How rigid s=
hould these things be, or should I breakdown and make and add, remove verbs=
 hanging off the end like this:</div><div><div style=3D"background-color: r=
gb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-w=
ord; " class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><span style=3D"color: #080;" class=3D"styled-by-prettify">/figh=
t/</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">fightId</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">}/</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">add</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">?</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">category</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">fight</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify">id</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">f=
ighterId</span></div></code></div></div><div>which seems complicated and yu=
cky.</div><div><br></div><div>I hope I am clear-ish. Thank you in advance,<=
/div><div><br></div><div>Aaron</div><div><br></div>
------=_Part_962_29403002.1349234497795--

------=_Part_961_4062540.1349234497795--