tags:

views:

17

answers:

1

Hi, I'm new to REST and I'm building a service using the WCF REST Starter Kit Preview 2 in C#. Most examples showing how to define a UriTemplate assume that you know the exact format of the URL and can pick out the bits you need to perform the request. But...

How do I allow users to enter a URL that defines a hierarchy and how do I process it? e.g. say I want to provide an online file-storage facility that allows user to view the contents of "folders" (all served from a database - not physical folders of course)

http://mysite.com/MyService/Folder/root/level1/level2/level3

i.e. the user wants to list the contents of a "Folder" that is specified as "root/level1/level2/level3". I can then take this path and serve data from my DB based on this info.

Thanks!

+1  A: 

You can use a wildcard (*) in your UriTemplate. For example:

[WebGet(UriTemplate="Folder/{*path}")]
public List<Files> GetStuff(string path) {
  //path is 'root/level1/level2/level3', which you can then parse
}

Here's a link on MSDN that provides a description and the rules around UriTemplates (rules are about 1/2 way down). The main thing to keep in mind is that you can only have one wildcard segment for a template string. Hopefully this helps!

BTW, the link is to MSDN docs for .NET 4. I think this also applies to 3.5.

David Hoerster
Excellent. Thanks!
jqwha
Glad I could help. If this helped, you should mark it as the answer - it will also help your answer accept rate (0 for 4).
David Hoerster