On Monday, February 4, 2013 12:16:12 PM UTC-7, mythz wrote:
Because it only should accept a Request DTO (i.e. not just any object) and the url is formatted according to the rules defined in the [Route] attributes.
The IReturn marker constrains it to a Request DTO. I only want to support Request DTO's with IReturn markers as it encourages the type info to be kept in 1 place (which is inferable by tooling/ServiceStack) as opposed to spreading the type info to all the different call sites.
A "T.Get" method issues a HTTP GET Method that doesn't have a HTTP Request body so all the data on the DTO needs to be transformed into a URL.
This doesn't happen when using a Send/Post (which uses a HTTP POST) or Put methods which have the opportunity to just send the serialized Request DTO into the Request body.
Actually, it turns out that Get() cannot take a URL + a request DTO implementing IReturn. So if you are doing custom routing (avoiding using the route parameters due to the separation of concerns issues mentioned in
http://stackoverflow.com/questions/12549981/can-servicestack-services-contain-multiple-methods ), you really can't use Get() unless you want to format the URL yourself.
I'm curious whether other people have found that ServiceStack is hard to use without attribute-based routes.
Is Send() with "GET" the best workaround? I'm looking at an extension method along these lines:
public static TResponse Get<TResponse>(this ServiceClientBase client, string relativeOrAbsoluteUrl, object request)
{
return client.Send<TResponse>("GET", relativeOrAbsoluteUrl, request);
}
(I could also have typed the request to be
IReturn<TResponse> instead of object.)
I know that when I get into the service, it has the request filled out, but did it do so in a non-standard way? It looks like ultimately, if you use "GET" or "HEAD", ServiceClientBase.PrepareWebRequest() will serialize the request to a string and append the string to the Uri anyway. So I don't see anything wrong with doing this.