RE: Updated URI Template proposal: unwieldy for query params

A common use case for a URI template will be building URIs with a set of optional query parameters. The query parameter name will not always match the variable names (the web server is free to choose the former; the latter may come from a standard).

I don’t think Joe’s current proposal can support this common use case.

Consider an Atom feed that supports the following URIs:
/feed?tag=foo&start=2&stop=7  -- return the 2nd to 7th entries that are tagged foo
The tag, start and stop parameters are all optional (they default to “any tag”, the first entry and the last entry respectively).
An Atom extension defines a field to hold a template for random access to the feed, which can use the variables “category”, “first” and “last”.

Template options:
1. /feed?tag={category}&start={first}&stop={last}
Sort of works, but creates ugly URIs when variables are undefined and assumes empty strings always mean default values.
2. /feed?{-join|&|tag,start,stop}
FAILS as the variable names don’t match the query parameter names.
3. /feed?{-prefix|tag=|category}{-prefix|&start=|first}{-prefix|&stop=|last}
Barely works. Produces “/feed?” instead of “/feed”; “/feed?&start=2” instead of “/feed?start=2”.
4. /feed{-opt|?|category,first,last}{-prefix|tag=|category}{-opt|&|category,first}{-prefix|start=|first}{-opt|&|category,last}{-prefix|stop=|last}
FAILS sometimes. It produces “/feed?start=2stop=7” instead of “/feed?start=2&stop=7”.
5. /feed{-opt|?|category,first,last}{-prefix|tag=|category}{-opt|&|category,first}{-prefix|start=|first}{-opt|&|category;first,last}{-prefix|stop=|last}
Works (technically), but an extra rule had to be introduced: “;” means OR (“,” means AND) in {-opt…}. It repeats variables names “category”, “first” and “last” 4, 3 and 3 times respectively. It requires 6 {…} elements. Adding another optional query parameter would involve modifying 1 existing {…} element and adding 2 more. Reordering parameters in the template requires modifying half of them. It is more than 100 characters longer than what should be possible.

It would be fantastic if the following template could be allowed for this common case.
Overhead is a minimal 6 characters.

From: [] On Behalf Of Joe Gregorio
Sent: Tuesday, 6 November 2007 4:32 AM
Subject: Updated URI Template proposal

where <op> is now a word, one of 'prefix', 'append',
'join', 'listjoin', 'opt', 'neg', or 'sub'.

Received on Thursday, 8 November 2007 02:00:41 UTC