geraintluff / uri-templates

JavaScript utility for RFC 6570: URI Templates
138 stars 21 forks source link

fromUri prints to console #3

Closed awwright closed 10 years ago

awwright commented 10 years ago

There's one instance of console.log in the library, in fromUri, which prints debugging information to the console. This should be removed.

(This library's from-URI resolving seems to be better than the one I was designing, so I'm adopting this. I'm calling fromUri many times per HTTP request, so this is important for optimization.)

This is also problematic in Web browsers where console may be not be a symbol.

geraintluff commented 10 years ago

Thanks for pointing this out. :)

I've released a fix as v0.1.2.

geraintluff commented 10 years ago

Could you give me some examples of the kind of things you're parsing?

I think there's some optimisation that could be done for simple cases like /{category}/{id}/, etc.

awwright commented 10 years ago

For now I'm just parsing stuff like {+subject} (if the URI is already in the database), or /user/{uid} to provide a user. Really the only obstacle is the one I described on the JSON Schema mailing list, where the "uid" variable is supposed to be returned as an integer, but currently, this fromURI function has no way of coercing the value.

My use cases may eventually become rather complex, in such a way that will have to be integrated in with JSON Hyper-Schema, I think. It will be stuff like /blog/{created.YYYY}/{created.MM}/{created.DD}/{title.URLFriendly}. Especially due to the last part (modifying the title to a 'URL friendly' version like replacing spaces with dashes), the way to handle this may be to generate the desired URL using this one-way URI Template, and store that as a database field, and do a reverse-lookup using e.g. /blog/{+subject}.