Code I have constructed so for:
public class RestService : IRestService
{
public async Task<StellaData> GetStellConfigData()
{
try
{
//Declare a Http client
HttpClient client = new HttpClient();
//Add a Base URl
//client.BaseAddress = new Uri(Constants.MUrl);
//Add the response type
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//Add the API
var response =await client.GetStringAsync(new Uri(Constants.mUrl));
var myItems = Newtonsoft.Json.JsonConvert.DeserializeObject<StellaData>(response);
return myItems;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
return null;
}
}
What I am trying to do:
- Set a Timeout for the request
- Catch Related Exception for the timeout for the request
- Get the response code for the request