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.236.83.235 with SMTP id q71mr683748yhe.5.1349235594028;
        Tue, 02 Oct 2012 20:39:54 -0700 (PDT)
X-BeenThere: api-craft@googlegroups.com
Received: by 10.236.154.232 with SMTP id h68ls1824436yhk.2.gmail; Tue, 02 Oct
 2012 20:39:51 -0700 (PDT)
Received: by 10.101.37.5 with SMTP id p5mr152155anj.25.1349235591821;
        Tue, 02 Oct 2012 20:39:51 -0700 (PDT)
Received: by 10.101.37.5 with SMTP id p5mr152154anj.25.1349235591760;
        Tue, 02 Oct 2012 20:39:51 -0700 (PDT)
Return-Path: <mikeschin...@gmail.com>
Received: from mail-yx0-f175.google.com (mail-yx0-f175.google.com [209.85.213.175])
        by gmr-mx.google.com with ESMTPS id u42si647588yhg.5.2012.10.02.20.39.51
        (version=TLSv1/SSLv3 cipher=OTHER);
        Tue, 02 Oct 2012 20:39:51 -0700 (PDT)
Received-SPF: pass (google.com: domain of mikeschin...@gmail.com designates 209.85.213.175 as permitted sender) client-ip=209.85.213.175;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of mikeschin...@gmail.com designates 209.85.213.175 as permitted sender) smtp.mail=mikeschin...@gmail.com; dkim=pass header...@gmail.com
Received: by yenm2 with SMTP id m2so2049526yen.6
        for <api-craft@googlegroups.com>; Tue, 02 Oct 2012 20:39:51 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=from:content-type:message-id:mime-version:subject:date:references
         :to:in-reply-to:x-mailer;
        bh=mCbAm438PCBOipRTgXrzWvCON+B2wW16K1Bv6FaFpTM=;
        b=Mz0fuhem+szt2jLsoSh5pSYyONTeWTc+2v3BVgH619M0ARzrA4OGUFSjav718nnd2e
         tOvJ/4U1ChsjuKax5SxSir1Ioq+Ic0pgjn/AifzQtr+B4hTWyz+YRigsM7ATlST/dZPp
         I6moJTE3tr763VbcDXHZUpP1ID8+2YEuphBpGtngZ5VNv/L0DwGEEyNDMFr+Q7kZu1LP
         SG3Zb8nFR8sL/Fnp5j+PNnF97b2mEhaY1+v4R0bC0GjhGvQwaJdxbGrXd6lmI44pVyYQ
         nPQzHkqgs9qUgW2XbtkbWvPAATFWXTx0ovI0DCQJSt4+Ee23IloKat4JuScT3QFcvbpc
         1hAA==
Received: by 10.236.73.36 with SMTP id u24mr741349yhd.103.1349235591587;
        Tue, 02 Oct 2012 20:39:51 -0700 (PDT)
Return-Path: <mikeschin...@gmail.com>
Received: from [192.168.1.108] (c-76-97-65-45.hsd1.ga.comcast.net. [76.97.65.45])
        by mx.google.com with ESMTPS id h22sm4246942yhk.13.2012.10.02.20.39.44
        (version=TLSv1/SSLv3 cipher=OTHER);
        Tue, 02 Oct 2012 20:39:51 -0700 (PDT)
From: Mike Schinkel <mikeschin...@gmail.com>
Content-Type: multipart/alternative; boundary="Apple-Mail=_849D35FE-07CF-4470-9321-6D7BDF246219"
Message-Id: <6CE09452-592B-4027-9992-5E280BD5C...@gmail.com>
Mime-Version: 1.0 (Mac OS X Mail 6.1 \(1498\))
Subject: Re: [api-craft] Best REST practises for adding and removing an element as opposed to deletion, and creation
Date: Tue, 2 Oct 2012 23:39:45 -0400
References: <71339652-66d8-4c09-a8e6-4b82d2e04f90@googlegroups.com>
To: api-craft@googlegroups.com
In-Reply-To: <71339652-66d8-4c09-a8e6-4b82d2e04f90@googlegroups.com>
X-Mailer: Apple Mail (2.1498)


--Apple-Mail=_849D35FE-07CF-4470-9321-6D7BDF246219
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=iso-8859-1

Hi Aaron,

Have you considered using PUT?  I'm not sure its the best approach, =
depends on your use case, but since you didn't mention it I though I'd =
bring it up If you can use PUT; others can advise if it's good or bad.

Here are what seem like some good articles on the subject:

http://www.markbaker.ca/2002/08/HowContainersWork/
=
http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-the-story=
/
http://stackoverflow.com/questions/630453/put-vs-post-in-rest
=
http://stackoverflow.com/questions/5686671/should-i-use-put-method-for-upd=
ate-if-i-also-update-a-timestamp-attribute

Hope this helps.

-Mike

On Oct 2, 2012, at 11:21 PM, Aaron Caswell <caswell.aa...@gmail.com> =
wrote:

> Hi Everybody,
>=20
> 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.
>=20
> Similarly,
> /fighters/
> /fighters/{fighterId}
> does the same for fighters.
>=20
> 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=3Dfight&id=3DfighterId
> which seems complicated and yucky.
>=20
> I hope I am clear-ish. Thank you in advance,
>=20
> Aaron
>=20
>=20
> --=20
> You received this message because you are subscribed to the Google =
Groups "API Craft" group.
> To unsubscribe from this group, send email to =
api-craft+unsubscribe@googlegroups.com.
> Visit this group at http://groups.google.com/group/api-craft?hl=3Den.
> =20
> =20


--Apple-Mail=_849D35FE-07CF-4470-9321-6D7BDF246219
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=iso-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Diso-8859-1"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi =
Aaron,<div><br></div><blockquote style=3D"margin: 0 0 0 40px; border: =
none; padding: 0px;"><div>Have you considered using PUT? &nbsp;I'm not =
sure its the best approach, depends on your use case, but since you =
didn't mention it I though I'd bring it up If you can use PUT; others =
can advise if it's good or bad.</div><div><br></div><div>Here are what =
seem like some good articles on the =
subject:</div><div><br></div></blockquote><blockquote style=3D"margin: 0 =
0 0 40px; border: none; padding: 0px;"><blockquote style=3D"margin: 0 0 =
0 40px; border: none; padding: 0px;"><div><a =
href=3D"http://www.markbaker.ca/2002/08/HowContainersWork/">http://www.mar=
kbaker.ca/2002/08/HowContainersWork/</a></div><div><a =
href=3D"http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-t=
he-story/">http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-o=
f-the-story/</a></div></blockquote></blockquote><blockquote =
style=3D"margin: 0 0 0 40px; border: none; padding: 0px;"><blockquote =
style=3D"margin: 0px 0px 0px 40px; border: none; padding: 0px; "><div><a =
href=3D"http://stackoverflow.com/questions/630453/put-vs-post-in-rest">htt=
p://stackoverflow.com/questions/630453/put-vs-post-in-rest</a></div><div><=
a =
href=3D"http://stackoverflow.com/questions/5686671/should-i-use-put-method=
-for-update-if-i-also-update-a-timestamp-attribute">http://stackoverflow.c=
om/questions/5686671/should-i-use-put-method-for-update-if-i-also-update-a=
-timestamp-attribute</a></div><div><br></div></blockquote>Hope this =
helps.</blockquote><blockquote style=3D"margin: 0px 0px 0px 40px; =
border: none; padding: 0px; =
"><div><br></div></blockquote>-Mike<br><div><br><div></div></div><div>On =
Oct 2, 2012, at 11:21 PM, Aaron Caswell &lt;<a =
href=3D"mailto:caswell.aa...@gmail.com">caswell.aa...@gmail.com</a>&gt; =
wrote:</div><div><div><br class=3D"Apple-interchange-newline"><blockquote =
type=3D"cite"><div>Hi Everybody,</div><div><br></div><div>I am sure this =
must have been answered well somewhere before, but I can't seem to find =
an answer that satisfies 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 restfully. 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"><span style=3D"color: =
#080;" class=3D"styled-by-prettify">/fights/</span> <span style=3D"color: =
#660;" class=3D"styled-by-prettify">-&gt;</span> all the fights that =
exist<br><span style=3D"color: #660;" =
class=3D"styled-by-prettify">/</span>fights<span style=3D"color: #660;" =
class=3D"styled-by-prettify">/{</span>fightId<span style=3D"color: =
#660;" class=3D"styled-by-prettify">}</span> <span style=3D"color: =
#660;" class=3D"styled-by-prettify">-&gt;</span> gives me fight =
fightId</code></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>Similarly,</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"><span style=3D"color: #080;" =
class=3D"styled-by-prettify">/fighters/</span><br><span style=3D"color: =
#660;" class=3D"styled-by-prettify">/</span>fighters<span style=3D"color: =
#660;" class=3D"styled-by-prettify">/{</span>fighterId<span =
style=3D"color: #660;" =
class=3D"styled-by-prettify">}</span></code></div><div>does the same for =
fighters.</div><div><br></div><div>Now, it makes sense to me that a GET =
on the following 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"><span style=3D"color: =
#080;" class=3D"styled-by-prettify">/fights/</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">{</span>fightId<span style=3D"color: =
#660;" class=3D"styled-by-prettify">}/</span>fighters<span style=3D"color:=
 #660;" class=3D"styled-by-prettify">/</span></code></div></div><div>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?</div><div>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.</div><div>How =
rigid should 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: rgb(250, 250, 250); border: 1px solid =
rgb(187, 187, 187); word-wrap: break-word; " class=3D"prettyprint"><code =
class=3D"prettyprint"><span style=3D"color: #080;" =
class=3D"styled-by-prettify">/fight/</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span>fightId<span style=3D"color: #660;" =
class=3D"styled-by-prettify">}/</span>add<span style=3D"color: #660;" =
class=3D"styled-by-prettify">?</span>category<span style=3D"color: =
#660;" class=3D"styled-by-prettify">=3D</span>fight<span style=3D"color: =
#660;" class=3D"styled-by-prettify">&amp;</span>id<span style=3D"color: =
#660;" =
class=3D"styled-by-prettify">=3D</span>fighterId</code></div></div><div>wh=
ich seems complicated and yucky.</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><div><br =
class=3D"webkit-block-placeholder"></div>

-- <br>
You received this message because you are subscribed to the Google =
Groups "API Craft" group.<br>
To unsubscribe from this group, send email to <a =
href=3D"mailto:api-craft+unsubscribe@googlegroups.com">api-craft+unsubscri=
be@googlegroups.com</a>.<br>
Visit this group at <a =
href=3D"http://groups.google.com/group/api-craft?hl=3Den">http://groups.go=
ogle.com/group/api-craft?hl=3Den</a>.<br>
&nbsp;<br>
&nbsp;<br>
</blockquote></div><br></div></body></html>=

--Apple-Mail=_849D35FE-07CF-4470-9321-6D7BDF246219--