I wrote a class that uses RestSharp to access Rest and HTTP API web services. I tested it and it works however I was wondering if any changes could be made to it to make it better.
public class RequestHandler
{
//Client to translate Rest Request intot HTTP request and process the result.
private RestClient client;
//this property stores the base URL
const string baseUrl = "";
//stores the account id and secret key if they will be needed for any authentication processes.
readonly string account_id;
readonly string secretKey;
//this property stores the API key
readonly string accessKey = "";
//This constructor contains the account id and secret key that will be used for authorization when connecting to the API
public RequestHandler(string account_id,string secretKey)
{
client = new RestClient(baseUrl);
this.account_id = account_id;
this.secretKey = secretKey;
}
//The default constructor
public RequestHandler()
{
client = new RestClient(baseUrl);
}
public void Execute<T>(int id,Action<T> Success, Action<string> Failure) where T:new()
{
RestRequest request = new RestRequest();
request.RequestFormat = DataFormat.Json;
request.AddParameter("id",id,ParameterType.GetOrPost);
client.ExecuteAsync<T>(request,(response) =>
{
if(response.ResponseStatus == ResponseStatus.Error)
{
Failure(response.ErrorMessage);
}
else
{
Success(response.Data);
}
});
}
}