For example, if I have standard request and response DTOs, linked up via IReturn<T>, what are the reasons to have a service method signature like the following, as seen in various online examples (such as this one, although not consistently throughout):
public object Get(DTO.MyRequest request)
rather than:
public IList<DTO.MyResponse> Get(DTO.MyRequest request)
Is an object return type here simply to support service features like gzip compression of the output stream, which results in the output being a byte array? It seems that one would want to have the appropriate stronger return type from these so-called “action” calls, unless I’m missing some common scenario or use case.
It used to be a limitation that the New API only supported an
objectreturn type, but that hasn’t been the case for a while where all examples on the New API wiki page now use strong-typed responses.One of the reasons where you might want to return an object return type is if you want to decorate the response inside a HttpResult, e.g:
It’s also useful if you want to return different responses based on the request (though it’s not something I recommend), e.g:
If you do choose to return an
objectI highly recommend decorating your Request DTO with theIReturn<T>marker to give a hint to ServiceStack what the expected response of the service should be.