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.
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:
> 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.
> Visit this group at http://groups.google.com/group/api-craft?hl=en.
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:
> 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:
> On Oct 2, 2012, at 11:21 PM, Aaron Caswell <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.
> 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.
> Visit this group at http://groups.google.com/group/api-craft?hl=en.
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:
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:
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.
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
On Tuesday, 2 October 2012 20:21:37 UTC-7, Aaron Caswell 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.
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
On Wednesday, 3 October 2012 02:08:07 UTC-7, Jon Moore wrote:
> 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:
> On Oct 3, 2012, at 1:47 AM, "Aaron Caswell" <caswel...@gmail.com<javascript:>> > 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 <mikesc...@gmail.com<javascript:> > > 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:
>> On Oct 2, 2012, at 11:21 PM, Aaron Caswell <caswel...@gmail.com<javascript:>> >> 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+...@googlegroups.com <javascript:>. >> 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+...@googlegroups.com <javascript:>. >> 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+...@googlegroups.com <javascript:>. > Visit this group at http://groups.google.com/group/api-craft?hl=en.