Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Plurals and Exposed Identifiers in URLs with RESTful Rails

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not that experienced with Rails (and Ruby in general) but I'm working on an java based web api that is using the REST architectural style and I'm curious about some of the design decisions that went into the new RESTful features of Rails.

1) Plurals in URLs (i.e., www.foo.com/users/1 instead of www.foo.com/user/1). This makes sense to me and most RESTful apis seem to follow this convention, but I can't seem to find a good explanation for why. I am choosing to use plurals because semantically it just seems more correct and while URLs should be opaque to the code they should also be understandable to the human reading them.

2) Exposing identifiers (i.e., www.foo.com/users/1 instead of www.foo.com/users/myusername). In theory, I'm against exposing identifiers, but in practice it's a often a pain to deal with surrogate human readable keys. I'd prefer that the whole URL was human readable, but I'm resorting to exposing identifiers because it's just easier with the data we have.


Does anyone know if Rails chose these conventions for any particular reason? Did it just fit better with existing Rails conventions?

-Michael
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IDs are better for the same reason that database keys should not be an attribute - because attributes can change. This is better for the user, too, by the way, due to bookmarking.
 
Michael J. Makunas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Doug Hall:
IDs are better for the same reason that database keys should not be an attribute - because attributes can change. This is better for the user, too, by the way, due to bookmarking.



I didn't mean use an attribute. I meant choosing between using the numeric primary key versus a human readable surrogate key (that doesn't change). Also, while you are correct, a URI should ideally not change over time, properly used 301 redirects can help.
 
Doug Hall
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Michael J. Makunas:


I didn't mean use an attribute. I meant choosing between using the numeric primary key versus a human readable surrogate key (that doesn't change). Also, while you are correct, a URI should ideally not change over time, properly used 301 redirects can help.



Yes, but that's a maintenance nightmare, over time. IDs never need a redirect because they never change. Also, they uniquely identify the resource in question. Suppose you had two Tom Jones' in your organization. Do you have one URL "http://myorg.com/employees/tomjones"; and the other "http://myorg.com/employees/tom_jones"? Who will know which is which, by looking at it? Yes, it's still more readable than numeric IDs, but it brings its own set of problems to the table.

Perhaps the user could just as easily do a search, and then bookmark it, if they need it more than once.

Cheers,
Doug
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pardon me if I misread but here may be a partial solution.

Rails URLs
 
You've gotta fight it! Don't give in! Read this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic