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
Best REST practises for adding and removing an element as opposed to deletion, and creation
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Aaron Caswell  
View profile  
 More options Oct 2 2012, 11:21 pm
From: Aaron Caswell <caswell.aa...@gmail.com>
Date: Tue, 2 Oct 2012 20:21:37 -0700 (PDT)
Local: Tues, Oct 2 2012 11:21 pm
Subject: Best REST practises for adding and removing an element as opposed to deletion, and creation

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Schinkel  
View profile  
 More options Oct 2 2012, 11:39 pm
From: Mike Schinkel <mikeschin...@gmail.com>
Date: Tue, 2 Oct 2012 23:39:45 -0400
Local: Tues, Oct 2 2012 11:39 pm
Subject: Re: [api-craft] Best REST practises for adding and removing an element as opposed to deletion, and creation

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-...
http://stackoverflow.com/questions/630453/put-vs-post-in-rest
http://stackoverflow.com/questions/5686671/should-i-use-put-method-fo...

Hope this helps.

-Mike

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Caswell  
View profile  
 More options Oct 3 2012, 1:47 am
From: Aaron Caswell <caswell.aa...@gmail.com>
Date: Tue, 2 Oct 2012 22:47:10 -0700
Local: Wed, Oct 3 2012 1:47 am
Subject: Re: [api-craft] Best REST practises for adding and removing an element as opposed to deletion, and creation

Thank you Mike. Very helpful links,

This is a tournament system for arbitrary duels. I have to be able to
generate a fight that will be scheduled for an arbitrary number of
combatants. Generating a fight and fighters is no problem. My sticky
use-case is that combatants may enlist or de-enlist themselves for the
battle up until the fight starts.
Yes, I think a PUT probably does make sense for an add fighter operation.
For example, supposing fighter 3 did not yet belong to fight 2, a PUT
to /fights/2/fighters/3 would make sense in this scenario.
I guess I have been reluctant to do this looking at some of the various
sources around the web that either propose creating a new element in such
scenarios if one does not exist (wikipedia), or just plain error-ing out if
performing a PUT to an element that does not exist (the apigee guys).
I have also seen patterns where an association resource is generated to
indicate connections among objects. In this scenario, I believe, I would go:
/fights/2/associations/3
where 3 is the globally unique id for fighter 3. Now, deleting and, a post
+ put combination would make sense for as crud ops to connect the fighter
to the fight. Deleting /associations/3 or fights/2/associations/3 both
would delete the same thing, yet not delete fighter 3. The thing is it adds
this weird associations resource that seems overly complicated. I hope I am
making sense.
So far I am liking the PUT solution and permitting DELETEs to
/fights/2/fighters/3 to just delete the association, not the actual fighter
when applied to this particular path.

Thank you again,

Aaron

On Tue, Oct 2, 2012 at 8:39 PM, Mike Schinkel <mikeschin...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Moore, Jonathan (CIM)  
View profile  
 More options Oct 3 2012, 5:08 am
From: "Moore, Jonathan (CIM)" <Jonathan_Mo...@Comcast.com>
Date: Wed, 3 Oct 2012 09:07:59 +0000
Local: Wed, Oct 3 2012 5:07 am
Subject: Re: [api-craft] Best REST practises for adding and removing an element as opposed to deletion, and creation

As others have suggested, a PUT to /fighters/{fightId}/fight may be the simplest, especially if these are true duels (two max participants). If you want to support more (battle royale!), you could consider doing a PATCH to remove someone.

I wrote up some suggestions for how to handle "list" resources like this here:

http://codeartisan.blogspot.com/2012/08/hypermedia-programming-lists....

Jon

........
Jon Moore

On Oct 3, 2012, at 1:47 AM, "Aaron Caswell" <caswell.aa...@gmail.com<mailto:caswell.aa...@gmail.com>> wrote:

Thank you Mike. Very helpful links,

This is a tournament system for arbitrary duels. I have to be able to generate a fight that will be scheduled for an arbitrary number of combatants. Generating a fight and fighters is no problem. My sticky use-case is that combatants may enlist or de-enlist themselves for the battle up until the fight starts.
Yes, I think a PUT probably does make sense for an add fighter operation. For example, supposing fighter 3 did not yet belong to fight 2, a PUT to /fights/2/fighters/3 would make sense in this scenario.
I guess I have been reluctant to do this looking at some of the various sources around the web that either propose creating a new element in such scenarios if one does not exist (wikipedia), or just plain error-ing out if performing a PUT to an element that does not exist (the apigee guys).
I have also seen patterns where an association resource is generated to indicate connections among objects. In this scenario, I believe, I would go:
/fights/2/associations/3
where 3 is the globally unique id for fighter 3. Now, deleting and, a post + put combination would make sense for as crud ops to connect the fighter to the fight. Deleting /associations/3 or fights/2/associations/3 both would delete the same thing, yet not delete fighter 3. The thing is it adds this weird associations resource that seems overly complicated. I hope I am making sense.
So far I am liking the PUT solution and permitting DELETEs to /fights/2/fighters/3 to just delete the association, not the actual fighter when applied to this particular path.

Thank you again,

Aaron

On Tue, Oct 2, 2012 at 8:39 PM, Mike Schinkel <mikeschin...@gmail.com<mailto:mikeschin...@gmail.com>> wrote:
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-...
http://stackoverflow.com/questions/630453/put-vs-post-in-rest
http://stackoverflow.com/questions/5686671/should-i-use-put-method-fo...

Hope this helps.

-Mike

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

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

--
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<mailto:api-craft+unsubscribe@googleg roups.com>.
Visit this group at http://groups.google.com/group/api-craft?hl=en.

--
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<mailto:api-craft%2Bunsubscribe@googl egroups.com>.
Visit this group at http://groups.google.com/group/api-craft?hl=en.

--
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<mailto:api-craft+unsubscribe@googleg roups.com>.
Visit this group at http://groups.google.com/group/api-craft?hl=en.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Caswell  
View profile  
 More options Oct 3 2012, 3:50 pm
From: Aaron Caswell <caswell.aa...@gmail.com>
Date: Wed, 3 Oct 2012 12:50:01 -0700 (PDT)
Local: Wed, Oct 3 2012 3:50 pm
Subject: Re: Best REST practises for adding and removing an element as opposed to deletion, and creation

That's a great approach.  I really like the idea of using PATCH'es to
update lists. A new verb! By the way, your diff insertion method is a
slick, general method to parametrize insertions. I am going to follow your
blog for sure. Good stuff in there. Thank you,
Aaron


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Caswell  
View profile  
 More options Oct 3 2012, 4:00 pm
From: Aaron Caswell <caswell.aa...@gmail.com>
Date: Wed, 3 Oct 2012 13:00:50 -0700 (PDT)
Local: Wed, Oct 3 2012 4:00 pm
Subject: Re: [api-craft] Best REST practises for adding and removing an element as opposed to deletion, and creation

By the way, regarding battle-royales, I was seeking a good solution for
unbounded fighters joining a fight for the next version of this system: a
tournament system for arbitrary rumbles :P


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »