Another idea for URI templates

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Another idea for URI templates

Murray S. Kucherawy-2

Hi all,

 

I don’t have the URI template draft handy unfortunately (on a long flight), so I can’t confirm this, but I think I found something useful that I don’t believe the template draft currently handles.


If you have a template that includes “/{foo}”, then the “/” is always inserted into the template regardless of whether or not “foo” is actually defined.  It might be nice to have the “/” be there only if “foo” is set.  Maybe something like “{?foo/}”, which means:

 

-          If “foo” is not set, append the empty string.

-          If “foo” is set but empty, append “/” and the name “foo” only.

-          If “foo” is set to a string, append “/”, then the name, then “=”, then the value.

-          If “foo” is set to a list, append “/”, then the name, then “=”, then the list elements separated by “,”.

-          If “foo” is set to a key-value set, append “/”, then the first key, then “=”, then the first value; for all remaining key-value pairs, append “&”, the next key, then “=”, then its matching value. (The name is not actually inserted into the template.)

 

So then a template of http://example.com/query.php{?foo?} expands thus:

 

-          “foo” undefined: http://example.com/query.php

-          “foo” defined, but empty: http://example.com/query.php?foo

-          “foo” defined to string “bar”: http://example.com/query.php?foo=bar

-          “foo” defined to list “a,b,c”: http://example.com/query.php?foo=a,b,c

-          “foo” defined to key-value set “{a, 1}, {b, 2}, {c, 3}”: http://example.com/query.php?a=1&b=2&c=3

 

Am I wrong, and the URI template spec handles this?  Or does this warrant some consideration and development?

Thanks,

-MSK

 

Reply | Threaded
Open this post in threaded view
|

Re: Another idea for URI templates

Kev Burns

Pretty sure the path segment and query expansions do this already. However, the -07 spec is missing examples of empty or undefined inputs for these expansions.

- Kev

On Oct 25, 2011 2:50 AM, "Murray S. Kucherawy" <[hidden email]> wrote:
Reply | Threaded
Open this post in threaded view
|

Re: Another idea for URI templates

Roy T. Fielding
In reply to this post by Murray S. Kucherawy-2
On Oct 25, 2011, at 2:46 AM, Murray S. Kucherawy wrote:

> I don’t have the URI template draft handy unfortunately (on a long flight), so I can’t confirm this, but I think I found something useful that I don’t believe the template draft currently handles.
>
> If you have a template that includes “/{foo}”, then the “/” is always inserted into the template regardless of whether or not “foo” is actually defined.  It might be nice to have the “/” be there only if “foo” is set.

That is exactly what is defined for {/foo}.

....Roy


Reply | Threaded
Open this post in threaded view
|

Re: Another idea for URI templates

Roy T. Fielding
In reply to this post by Kev Burns
On Oct 25, 2011, at 7:10 AM, Kev Burns wrote:

> Pretty sure the path segment and query expansions do this already. However, the -07 spec is missing examples of empty or undefined inputs for these expansions.

Well, sec 3.2.6 does have one, but I combined it with another variable

    {/var,empty}       /value/
    {/var,undef}       /value

....Roy