Search code examples
restsharp

Convert IRestResponse to IRestResponse<T>


I have executed RestRequest and got non-typed IRestResponse.

How can I convert it to IRestResponse<T>?

For example IRestResponse<MyErrorData> or IRestResponse<MyData>?


Solution

  • You need to use the generic overload of Execute:

    var client = new RestClient();
    client.BaseUrl = BaseUrl;
    request.AddParameter("AccountSid", _accountSid, ParameterType.UrlSegment);
    var response = client.Execute<T>(request);
    

    Execute<T> is the key to getting back a typed response.