Re: URI Templates - optional variables?

On Oct 15, 2007, at 6:03 PM, Mark Nottingham wrote:
> On 16/10/2007, at 10:11 AM, Roy T. Fielding wrote:
>
>> I think it is critical to limit the potential operations to
>> typical string operations, both for simplicity of implementation
>> and also for our capacity to understand the template without
>> needing to refer to external rules or processing.  There is no
>> reason to have URI templates if we don't limit them to a
>> declarative syntax
>
> Agreed; I didn't mean to imply anything else. My concern was more  
> that we'd be able to cover the diversity of use cases we've heard  
> about (much less hadn't come across yet) with a reasonably-sized  
> library of operators in one go.

I was actually responding to Stefan's suggestion that we include
function names for arbitrarily namespaced actions.  If we are trying
to solve a declarative problem, we need to stick to self-descriptive
solutions.

> WRT "string operations": what about allowing variable values to be  
> lists of strings? E.g., this seems like it would be useful:
>
> template: http://example.org/sausage?{,&condiments}
> condiments = ["tomato sauce", "chutney", "relish"]
> result: http://example.org/sausage?condiments=tomato% 
> 20sauce&condiments=chutney&condiments=relish
>
> Otherwise, I've got to define condiment1, condiment2, and so on, or  
> fall back to simple substitution and build it myself.

I think that is mixing up Joe's join syntax and my param=value
substitution (the & operator is confusing, which is why I used
plus "+" for my simple joins and comma "," for param=value).

I am struggling to think of a use case for arrays in real practice.
I could understand modifying join such that it treats single variables
with array values the same as multiple variables with single values,
e.g,

   http://example.org/sausage?{+,|condiments} =
   http://example.org/sausage?condiments=tomato%20sauce,chutney,relish

but I can't think of a case where I would need that for a web service.
Also, how does the reader of the template know that the variable is
supposed to be an array?  Hmm, how about

   name    = "Roy"
   address = ["23 Corporate Plaza DR", "Suite 215",
              "Newport Beach, CA 92660", "USA"]

    http://example.org/checkaddress{,&|name,address} =
   <http://example.org/checkaddress?name="Roy"
     &address=23%20Corporate%20Plaza%20DR
     &address2=Suite%20215&address3=Newport%20Beach,%20CA%2092660
     &address4=USA>

That would work.  The ',' operator would then supply the template
reader with an expectation that multi-valued parameters should be
listed with a numeric suffix for values N>1.

An alternative would be to go the perl direction and add a form
of type annotation to the variable names, as in

    http://example.org/checkaddress{,&|name,@address}

but variable types might be a slope too slippery.

....Roy

Received on Tuesday, 16 October 2007 01:47:20 UTC