So I need to deal with spaces in REST URL's. Something like:
I'd rather not allow these types of URL's (since I don't think the spec even allows them) and was thinking about the programming and also community practices issues this raises. If a person wants a space they likely should use "%20", however this just doesn't look good and I believe gets confusing.
I could simply allow the community to create such URL's even though I believe them wrong and then attempt to resolve them in my Grails application with:
someString.replaceAll("%20", " ")
since firefox and I suspect other browsers will convert the spaces to "%20" for the user.
This seems a poor approach though since if someone puts two spaces into the URL or somehow a tab gets in things get ugly fast. A person just has far too many bad issues to deal with.
Forcing the community to use camel case (here I will use lower camel case but one could use upper camel case) would require a URL like:
where I could split the parameter in Groovy with:
someString.replaceAll("([A-Z])", " $1").trim()
so "lateJurassic" becomes "late Jurassic" which is what is in my database (actually "Late Jurassic" but I can case insensitive search) since that is the "proper" form of the name.
This puts the burden of creating a camel case representation of "Late Jurassic" on the client end of the application (ie, make this someone else's problem, which is always a good thing).
I suspect this is just a case where the best resource identifier in the database is not always the best resource identifier for the REST URL representation. It would seem then that apply a best practice approach one would use a camel case representation. This might be a situation where using upper camel case is better yet since the proper cases on the name is "Late Jurassic" resulting in a URL:
That is still fine since the .trim() call will remove the leading space still in the above code. I'd love to hear other thoughts on such mappings.