URI Templates (2012)
tools.ietf.org
tools.ietf.org
I mean, I love URI templates. They're neat, they're reversible, but they're not exactly new, right?
/{lista:*,listb:*}
+
"lista": [ "one", "two" ], "listb": [ "three", "four" ]
=
/one,two,three,four
Now, reverse it. You can't because there's no way of knowing which elements belong in which list. It's so annoyingly close to being a pure dual, but it's not. So I've had to make up some irksome rules for the edge cases like that which make me sad, but make matching using templates feasible (wise? maybe not, see note in spec, but that note wouldn't be even needed if only... sigh). URI Templates are a good example of why I wish I worked on IETF specs, while also being glad I don't...On another note, if you want it to be reversible, wouldn't you just slash-delimit the two lists?
"Some URI Templates can be used in reverse for the purpose of variable matching: comparing the template to a fully formed URI in order to extract the variable parts from that URI and assign them to the named variables. Variable matching only works well if the template expressions are delimited by the beginning or end of the URI or by characters that cannot be part of the expansion, such as reserved characters surrounding a simple string expression. In general, regular expression languages are better suited for variable matching."
(Of course, a lot of standards, and this is one, are reflections, and unifications, of existing implicit standards. People had already started using some of these features, so they couldn't really drop them, and still see adoption. Not an easy balance!)
Ambiguity was going to be possible either way - here's a Level 2 example:
/{+a}/{+b}
-> "/foo/bar/baz"
By "reversible" I meant it's possible to find something that reconstructs to the original URL (http://bit.ly/1H27rwD), much like you did.