About RESTful collections, what do people think about "the correct" way of returning empty collections with Rails+ActiveResource? Suppose I hit up a URI for a collection and the collection is empty. Should we return 404 or an empty container? I''m currently returning 404 and this causes the ActiveResource client application to raise ActiveResource::ResourceNotFound even on a find(:all), which is different than how ActiveRecord behaves in the analogous scenario. -- Bosko Milekic <bosko.milekic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> http://www.crowdedweb.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
(Appologies if this turns out to be a double-post... my first attempt does not appear to have gone through). About RESTful collections, what do people think about "the correct" way of returning empty collections with Rails+ActiveResource? Suppose I hit up a URI for a collection and the collection is empty. Should we return 404 or an empty container? I''m currently returning 404 and this causes the ActiveResource client application to raise ActiveResource::ResourceNotFound even on a find(:all), which is different than how ActiveRecord behaves in the analogous scenario. -- Bosko Milekic <bosko.milekic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> http://www.crowdedweb.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Sep 28, 2006, at 3:30 PM, Bosko Milekic wrote:> (Appologies if this turns out to be a double-post... my first attempt > does not appear to have gone through). > > About RESTful collections, what do people think about "the correct" > way of returning empty collections with Rails+ActiveResource? > > Suppose I hit up a URI for a collection and the collection is empty. > Should we return 404 or an empty container? I''m currently returning > 404 and this causes the ActiveResource client application to raise > ActiveResource::ResourceNotFound even on a find(:all), which is > different than how ActiveRecord behaves in the analogous scenario.I think I''d lean towards returning an empty list. As I see it, a 404 should be issued if you don''t recognise the concept of that resource, or if someone requests a specific resource that we don''t have, but if the collection exists and is empty, we should say so. In other words, if you have the resource types books and authors but not illustrators and the authors collection is empty I''d expect: GET /books -- a list of books GET /authors -- an empty list GET /authors/1 -- 404 GET /illustrators -- 404 James. -- James Stewart : Freelance Web Developer Work : http://jystewart.net Play : http://james.anthropiccollective.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 9/28/06, James Stewart <jystewart-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Sep 28, 2006, at 3:30 PM, Bosko Milekic wrote: > (Appologies if this turns out to be a double-post... my first attempt > does not appear to have gone through). > > About RESTful collections, what do people think about "the correct" > way of returning empty collections with Rails+ActiveResource? > > Suppose I hit up a URI for a collection and the collection is empty. > Should we return 404 or an empty container? I''m currently returning > 404 and this causes the ActiveResource client application to raise > ActiveResource::ResourceNotFound even on a find(:all), > which is > different than how ActiveRecord behaves in the analogous scenario. > I think I''d lean towards returning an empty list. As I see it, a 404 should > be issued if you don''t recognise the concept of that resource, or if someone > requests a specific resource that we don''t have, but if the collection > exists and is empty, we should say so. > > In other words, if you have the resource types books and authors but not > illustrators and the authors collection is empty I''d expect: > > GET /books -- a list of books > GET /authors -- an empty list > GET /authors/1 -- 404 > GET /illustrators -- 404 > > James.I agree with this rationale. I submitted ticket#6291 [1] a couple of days ago which fixed ARes in the single-element-in-collection edge case, and I just uploaded a new diff which also fixes ARes find_every when the collection is empty. [1] http://dev.rubyonrails.org/ticket/6291 -- Bosko Milekic <bosko.milekic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> http://www.crowdedweb.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---