views:

66

answers:

2

I am designing my namespace such that the id i am storing in the DB is

id -> "e:t:222"

where "e" represents the Event class, "t" represents the type

i am also expecting to use this id in my urls

url -> /events/t:222

Is there anything wrong with doing this?

+1  A: 

Is there anything wrong with doing this?

Yes: The colon is a reserved character in URLs that has a special meaning, namely specifying the server port, in a URL.

Using it in other places in the URL is a bad idea.

You would need to URLEncode the colon in order to use it.

Pekka
That's only true for the host part, the path can contain colons just fine. `schema://host:port/path?query#fragment` Not quite sure about Rails, but CakePHP uses `/name:value/` paths for pretty named parameters by default.
deceze
@deceze are you sure? Because RFC 1738 says `Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.`
Pekka
@deceze also see http://en.wikipedia.org/wiki/Percent-encoding#Types%5Fof%5FURI%5Fcharacters It's true that many sites use it, and the practice is tolerated by all browsers I know of, but I would be especially careful in regards to a REST web service... But I'm happy to stand corrected if I'm wrong.
Pekka
From [RFC 3986](http://tools.ietf.org/html/rfc3986#section-3.3): `Aside from dot-segments in hierarchical paths, a path segment is considered opaque by the generic syntax. URI producing applications often use the reserved characters allowed in a segment to delimit scheme-specific or dereference-handler-specific subcomponents.` The keyword here being **opaque**. It may be a reserved character, but it doesn't have any specific meaning in (certain parts of) the path. At least that's how I interpret it, and since it works, others seem to as well. :)
deceze
It's fun watching you two talk :)
Matchu
@Matchu Haggling over semantics in documentation *is* fun. It's like philosophy, only that there's a solution available. Or religion for that matter: "In Matthew 7:42 it says 'Thou shall not...'" ;P
deceze
I forgot about my original question to stand in awe of your amazing dictation of the RFC.
ming yeow
@deceze what you quote seems pretty watertight, so I stand corrected! Although it would have been fun to continue "Ah, but doesn't RFC xyz say...." :)
Pekka
I'm sure you could find an errata or superset or subset RFC somewhere that can be interpreted in a way such as to allow this to continue. ;)
deceze
A: 

There is nothing wrong with doing this, you'll simply need to encode the URL properly. Most libraries with do this automatically for you.

In general though, if you care about your data you shouldn't let the application drive the data or database design. Exceptions to this are application centric databases that have no life outside of a single application nor do you expect to use the data anywhere else. In this case, you may want to stick with schemas and idioms that work best with your application.

Stephen Petschulat