Reputation: 188
I am calling ThirdParty API using JsonServiceClient
.
var client = new JsonServiceClient(ServiceURL);
var response = client.Get<Output>("Search?id=" + id);
Output is class represent response coming from Third party API. I am able to get output correctly. But I want to capture StatusCode of this API response. How can I do this?
Note I have tried WebHttpResponse object instead of Output(response class). But I want statuseCode should be property of Output class not parameter of
WebHttpResponse
. Is there any way to achieve this?
Upvotes: 1
Views: 817
Reputation: 143359
You would need to use a response filter, e.g:
var client = new JsonServiceClient(ServiceURL) {
ResponseFilter = res => res.StatusCode.ToString().Print()
};
But ServiceStack Service Clients are only meant for consuming ServiceStack Services, for consuming 3rd party API's, I'd recommend using HTTP Utils instead, e.g:
var response = ServiceURL.CombineWith("Search").AddQueryParam("id",id)
.GetJsonFromUrl(responseFilter:res => res.StatusCode)
.FromJson<Output>();
Upvotes: 5