How do I pass a list of complex types in a query string?

How to pass a list of complex types to ServiceStack? For example, my DTO request looks like this:

//Request DTO public class Test { public IList<Fund> Funds { get; set; } } public class Fund { public string Key { get; set; } public int Percent { get; set; } } 

How to pass serial object via HTTP get?

 http://localhost:49490/api/funds={ ?? } 

KeyValueDataContractDeserializer: error to type conversion: type definitions must begin with the character '{', waiting for the serialized type 'Fund' to receive a string starting with: asdf

+8
servicestack
source share
1 answer

ServiceStack parses queryString using the JSV format, it is mostly JSON with quotes in CSV style (i.e. only quotes are needed when your value has an escape char) ..

Although you did not define a user route here, in most cases your user route matches your DTO request, which in this case Test has no means.

So, assuming the custom route looks like this:

 Routes.Add<Test>("/test"); 

You can call the service through a QueryString, for example:

HTTP: // local: 49490 / API / test Tools = [{Key: Key1, Percentage: 1}, {Key: Key2, Percentage: 2}]

On a side note, Interfaces on a DTO are usually a bad idea; you should avoid (at least limit) its use at all times.

+10
source share

All Articles