Nest Those Rails Resources Or Make Baby Semantic Web Cry
Proper web architecture dictates that a you should “Assign distinct URIs to distinct resources.” And Cool URIs for the Semantic Web states that:
There should be no confusion between identifiers for Web documents and identifiers for other resources. URIs are meant to identify only one of them, so one URI can’t stand for both a Web document and a real-world object.
So we know that a URI should refer to one and only one resource. (Of course, you may have many URIs all referring to the same resource.) So why do so many web sites have URIs like http://www.example.org/myaccount? That same URI is used to refer to any account in the system, depending on who is logged in. And that makes Baby Semantic Web cry.
Why is the baby sobbing? A generic URI like http://www.example.com/myaccount isn’t useful on the semantic web, because it’s very difficult to make meaningful statements about that URI. Let’s go and try.
http://www.example.com/myaccount is the account page of "Seth Ladd".
and
http://www.example.com/myaccount is the account page of "Bob Smith".
Hmm… so http://www.example.com/myaccount is the account page for both Seth and Bob? That doesn’t make much sense!
A better URI for an account page would be http://www.example.com/accounts/23232, which is easily unique for every user.
The moral of this story is that every one of your URIs should be unique. So let’s bring this all the way back to Rails and resources.
When building your resources, ask yourself, “If I GET this URI, will I see the same thing no matter who is logged in?” If the answer is “No” then you need to nest your resources so that the URI is unique and the same representation is returned no matter who you are logged in as.
For example, a typical URI would be http://www.example.com/books, which could easily be a collection of books for the user. The contents of that URI are relative to the person logged in, so we have a problem. To fully qualify the URI, we need to nest books inside of the user collection. We end up with http://www.example.com/users/1/books, which is unique and follows web architecture best practices. Now we can say unambiguous statements about the URI, thus populating the semantic web with more useful and meaningful triples.
April 2nd, 2008 at 11:09 pm
numbering the user(s) creates discussions like:

“oh yeah, i am user #2345, according to records, you’re only user #2367.”
April 3rd, 2008 at 1:07 am
the point being if your locked up in the ‘asylum’ you *cannot* get into the pub.
April 3rd, 2008 at 10:54 am
Related to the topic but not directly is how twitter does an account’s “home”. When logged into twitter my url to post twitters is located at “twitter.com/home”. I think it would be better to have me go to “twitter.com/techustle” to post.
I also notice that twitter gets jacked up if you are trying to twitter from two accounts while logged in. It can’t determine which account is tied to “twitter.com/home”.
April 3rd, 2008 at 11:06 am
Chris, That’s exactly what I’m talking about. Your home shouldn’t be some generic URI.
June 13th, 2008 at 10:51 pm
How about a redirect though?
twitter.com/home, which when user logged in, goes to
twitter.com/some_user
June 14th, 2008 at 6:55 am
Really? There’s no redirect for me.