See Configuring HTTP Responses ServiceStack widget page for all the different ways to configure an HTTP response.
A HttpResult is just one way to set up an HTTP response. Usually you want to enable Absolute Url if you are going to redirect it, for example:
public object Post(Todo todo) { var todo = ...; return new HttpResult(todo, HttpStatusCode.Created) { Location = base.Request.AbsoluteUri.CombineWith("/tada") }; }
Note. HTTP clients will never see the HttpResult DTO. HttpResult is not the DTO itself , it is only for capturing and modifying the configured HTTP response you want.
All ServiceStack clients return - this is the HTTP body, which in this case is the Todo Response DTO. The location is indeed added to the headers of the HTTP response, and to see the entire response of the HTTP response, you should use an HTTP sniffer like Fiddler, WireShark or Chrome WebInspector.
If you want to access it using ServiceStack HTTP clients, you will need to add a response filter that will give you access to HttpWebResponse , for example:
restClient.ResponseFilter = httpRes => { Assert.Equal(httpRes.Headers[HttpHeaders.Location], "/tada"); }; Todo todo = restClient.Post(new Todo { Content = "New TODO", Order = 1 });
Checking response headers using web request extensions
Another lightweight alternative if you just want to check the HTTP response is to use the ServiceStack Convenient WebRequest extension methods, for example:
var url = "http://path/to/service"; var json = url.GetJsonFromUrl(httpRes => { Assert.Equal(httpRes.Headers[HttpHeaders.Location], "/tada"); });
mythz
source share