Hierarchical paths with parameters

Topics: Web Api
Mar 17, 2011 at 9:43 PM
Edited Mar 17, 2011 at 9:46 PM

Hi - is there any support in WCF HTTP APIs to support hierachical paths? Most examples I've seen are based in a structured path - e.g. /products, etc. I would like to be able to model 'real world' heirachical paths, allowing users to create custom paths for their resources. It would be useful if these paths could support paramters - e.g. /this/is;parameter=value&parameter2=value/my/example/path and these be extracted. If this hasn't yet been supported, would it be possible to create processors that would work that way?


Mar 17, 2011 at 10:13 PM

Can you give an example of the kind of path you mean? With WCF HTTP you can create complex paths with a uri template, including additional parameters in the segments that are separated by literals. Here is a link to more information on what UriTemplate supports; http://msdn.microsoft.com/en-us/library/bb675245.aspx

Now if you are using ASP.NET, our ServiceRoute does not support this, but you can combine a base address in a route with UriTemplates on the service.

Mar 17, 2011 at 11:09 PM

I would envisage that the individual segments of the path would have no special meaning other than indicating to the service the 'path' to the resource that is being requested. I assume this would require a wildcard in the template - e.g /{*path} ?

Mar 17, 2011 at 11:11 PM

We allow wildcards, literals and variables.

i.e. you can do foo/bar or {foo}/{bar} or foo/* for example.


Mar 17, 2011 at 11:17 PM

The ";" syntax also is supported. So for example I just tested this template and it worked fine:

[WebGet(UriTemplate = "Foo/Bar;b={Baz}")]
public void Get(HttpResponseMessage response, string baz)

In this case when I pass in this uri: "/Foo/Bar;b=barbaz", I get the value 'barbaz" in the method.

Mar 18, 2011 at 9:38 AM

Thanks - I'll try that

I think what I need is something more advanced - what I would like to do is to use the ; parameters within the segments, not just the last one. For instance, one might have collections of resources:


but let's say we don't necessary know tha name of the collection at level 2, but we have criteria to find it, so:


I am thinking that this is too specific to be supported out the box - but using a wildcard, I could do the parsing within the service to break apart the segments?