Supporting arrays of values

Topics: Web Api
Jun 16, 2011 at 3:11 AM

All of the built-in types are readily supported for automatic conversion from the string value returned by the UriTemplateHandler to the operation parameter type (i.e. int, bool, etc.).

However, arrays of those same types are not supported, even though from the URI point of view, they always are. (query strings are parsed to NameValueCollection, which can always have multi-valued keys, and this is indeed what UriTemplate uses internally too).

This makes it quite inconvenient to support simple arrays that would be simple enough to build from the client (i.e. "/products?tag=wpf&tag=wcf").

It would be nice if the built-in behavior was extended to support this scenario without requiring custom operation handlers for each possible type of array.

 

Coordinator
Jun 16, 2011 at 5:27 AM

Thanks Daniel. I'm going to file a bug to see what we can do here. For now you could create your own dervied handler and replace ours with your own via a custom handler factory.

Glenn

Jun 16, 2011 at 7:18 AM
yup, done that.

it's in the netfx-WebApi.QueryableService nuget.

it only exposes multi-value query string parameters as string arrays, no other array types supported. It's essentially a minimally tweaked UriTemplateHandler that I hook up with the rest of the queryable support via the HttpQueryableServiceHost.

it's all working smoothly now together with the "linq to web api" in netfx-System.Net.Http.HttpEntityClient :)

/kzu
Coordinator
Jun 16, 2011 at 7:33 AM

You're an animal :-)