How would I pass a list of complex types in ServiceStack? For example my Request DTO 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 can I pass the serialized object via HTTP get?
http://localhost:49490/api/funds={ ?? }
KeyValueDataContractDeserializer: Error converting to type: Type definitions should start with a '{', expecting serialized type 'Fund', got string starting with: asdf
A query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML, choosing the appearance of a page, or jumping to positions in multimedia content.
A querystring is a set of characters input to a computer or Web browser and sent to a query program to recover specific information from a database .
ServiceStack parses the queryString using the JSV Format this is basically JSON with the CSV-style quotes (i.e. only needs quotes when your value has an escape char).
Although you haven't defined a Custom Route here, in most cases your custom route is the same as your Request DTO which in this case is Test not /funds.
So assuming a custom route looks like:
Routes.Add<Test>("/test");
You can call your service via a QueryString like:
http://localhost:49490/api/test?Funds=[{Key:Key1,Percent:1},{Key:Key2,Percent:2}]
On a side note Interfaces on DTOs are generally a bad idea, you should consider avoiding (at least limiting) its use at all times.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With