Re: URI Templates - optional variables?


I've been lurking here for a bit and have read the threads on Joe's 
latest proposal. Like Marc Hadley, I see the ability to match templates 
to URIs and extract values of variables as valuable because it allows 
the same template to be used to both generate and parse, so there is no 
possibility of the spec for the client to be out of sync with the 
behavior of the server.

While Joe and John Cowan are correct that the current proposal is not 
generally invertible, it seems to me that the only interesting templates 
are those that are invertible--otherwise how would the server infer what 
the client meant?

I've written a template parser (in Java) that can go in either direction 
(template+variables->URI or URI+template->template). It resolves 
ambiguities by matching greedily.

Here are John's and Joe's examples of ambiguous matches, with my 
program's resolution of them.

Template:   /{foo}{bar}/
URI:        /whatever/
Variables:  foo => 'whatever', bar => ''

Variables:  a => 'true', b => null

It might be difficult to specify a non-ambiguous language. It might be 
worthwhile to warn users of the pitfalls of non-reversible templates.

Once I can get my employer's OK, I'll pass my code along to Joe in case 
he wants to put it up on the uri-templates Google Code site.

Jim Ancona

Received on Friday, 2 November 2007 22:17:30 UTC