Reputation: 2112
I am writing a client wrapper over a RESTful API which can take more than one value for an argument.
Take for example this endpoint
/rest/bug?product=Foo&product=Bar
My class for this is
public class SearchBugRequest : IReturn<BugResponse>
{
[DataMember(Name = "product")]
public string[] Product { get; set; }
}
When I use ToUri
it shows that the ServiceStack is constructing the URI as
/rest/bug?product=Foo%2CBar%2CBlah
ServiceStack is ending up creating a URL which is comma-seperated and URL encoded
How do I force ServiceStack to create the URL which the service expects?
Upvotes: 0
Views: 77
Reputation: 143284
You should only be using ServiceStack's Typed Clients to talk to ServiceStack Services not an external 3rd Party REST API as they're primarily designed to generate HTTP Requests that are natively understood by ServiceStack Services.
If you want to consume 3rd Party Services it's recommended to use the more flexible and customizable HTTP Utils API's instead.
Having said that you can customize the generated Url to generate the url you want using an IUrlFilter with something like:
public class SearchBugRequest : IReturn<BugResponse>, IUrlFilter
{
[IgnoreDataMember]
public string[] Product { get; set; }
public string ToUrl(string absoluteUrl)
{
Product.Each(p => absoluteUrl = absoluteUrl.AddQueryParam("product",p));
return absoluteUrl;
}
}
Upvotes: 2