michael.raidel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Nov-27 23:04 UTC
Consistency in REST-routes naming
Hello everyone! In working with the Rails-REST-features I have always wondered about the URL for the new-action /objects/new In REST the URL should represent a Resource. As the semicolon is for adding non-standard actions (verbs) to a resource, IMHO it should be: /objects;new and not /objects/new In fact, this is just like an additional action, which I would specify with the :collection-parameter: map.resources :objects, :collection => { :special_action => :get } which would look like /objects;special_action and not like /objects/special_action Also the edit-action is implemented this way: /objects/1;edit What do you think? Have a nice day, Michael --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
michael.raidel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> In REST the URL should represent a Resource. As the semicolon is for > adding non-standard actions (verbs) to a resource, IMHO it should be: > > /objects;new > and not > /objects/new"/objects;new" would refer to listing a collection of objects with a "new" aspect. "/objects/new" means that it should show one object with that does not have an id. Make any sense? DHH has done his research and its definitely right the way it is. I thought it was odd the first time I saw it too. -- Josh Peek josh at joshpeek dot com http://joshpeek.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?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/27/06, michael.raidel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <michael.raidel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello everyone! > > In working with the Rails-REST-features I have always wondered about > the URL for the new-action > > /objects/new > > In REST the URL should represent a Resource. As the semicolon is for > adding non-standard actions (verbs) to a resource, IMHO it should be: > > /objects;new > and not > /objects/new > > In fact, this is just like an additional action, which I would specify > with the :collection-parameter: > > map.resources :objects, :collection => { :special_action => :get } > > which would look like > /objects;special_action > and not like > /objects/special_action > > Also the edit-action is implemented this way: > /objects/1;edit > > What do you think? > > Have a nice day, > > MichaelThe problem is that you''re thinking in terms of the database, when you need to be thinking in terms of resources. When you request /objects/1, you''re not getting an object from the db that has an id of 1, but simply requesting an object identified by "1". Then you do something interesting with it. The underlying implementation doesn''t matter one bit, nor should it. We''re using the web, where everything is a resource. In the same vein, when you request /objects/new you''re not requesting a new object, nor are you making an RPC call to Object.new. All you''re doing is requesting the resource identified by /objects/new. The difference between this resource and the /objects/1 from earlier is that, by convention, you can''t update this particular resource. This isn''t really a web convention, but rather one that Rails gives you with the default code. You could just as easily write some code that WOULD allow you to update the resource at /objects/new. This may seem a bit confusing, and it''s likely because I''m not a very eloquent writer. However it''s important that you recognize the paradigm here - it''s not about databases, it''s not about procedures, it''s about resources. I recommend reading DHH''s "A World of Resources" [1] and Alex Bunardzic''s various blog posts on resources [2]. Hopefully they''ll help it click for you, as well help you recognize the importance of this approach. Pat [1] http://www.loudthinking.com/arc/000593.html [2] http://jooto.com/blog/index.php/category/resource-oriented-architecture/ --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you for your answers! I understand your argumentation, although I think one could argue it also the other way round. PUT /objects/1 updates the object as we have no standard-verb to get the form we use GET /objects/1;edit IMHO this would be in the same spirit as the relation between POST /objects GET /objects;new and in fact this is exactly the syntax DHH used in the presentation you mentioned (look on page 18) But of course I also understand the argumentation with /objects/new being it''s own resource and have no problem with this syntax. For me the ";new"-syntax is just a bit more self-explanatory, I would see the new-form as an aspect of the collection, as the edit-form is an aspect of the member). Michael 2006/11/28, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > On 11/27/06, michael.raidel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <michael.raidel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hello everyone! > > > > In working with the Rails-REST-features I have always wondered about > > the URL for the new-action > > > > /objects/new > > > > In REST the URL should represent a Resource. As the semicolon is for > > adding non-standard actions (verbs) to a resource, IMHO it should be: > > > > /objects;new > > and not > > /objects/new > > > > In fact, this is just like an additional action, which I would specify > > with the :collection-parameter: > > > > map.resources :objects, :collection => { :special_action => :get } > > > > which would look like > > /objects;special_action > > and not like > > /objects/special_action > > > > Also the edit-action is implemented this way: > > /objects/1;edit > > > > What do you think? > > > > Have a nice day, > > > > Michael > > The problem is that you''re thinking in terms of the database, when you > need to be thinking in terms of resources. When you request > /objects/1, you''re not getting an object from the db that has an id of > 1, but simply requesting an object identified by "1". Then you do > something interesting with it. The underlying implementation doesn''t > matter one bit, nor should it. We''re using the web, where everything > is a resource. > > In the same vein, when you request /objects/new you''re not requesting > a new object, nor are you making an RPC call to Object.new. All > you''re doing is requesting the resource identified by /objects/new. > The difference between this resource and the /objects/1 from earlier > is that, by convention, you can''t update this particular resource. > This isn''t really a web convention, but rather one that Rails gives > you with the default code. You could just as easily write some code > that WOULD allow you to update the resource at /objects/new. > > This may seem a bit confusing, and it''s likely because I''m not a very > eloquent writer. However it''s important that you recognize the > paradigm here - it''s not about databases, it''s not about procedures, > it''s about resources. I recommend reading DHH''s "A World of > Resources" [1] and Alex Bunardzic''s various blog posts on resources > [2]. Hopefully they''ll help it click for you, as well help you > recognize the importance of this approach. > > Pat > > > > [1] http://www.loudthinking.com/arc/000593.html > [2] http://jooto.com/blog/index.php/category/resource-oriented-architecture/ > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---