Generic Implementation for Api call in c# i have created one generic implementation for api call from all over my application.

 public class HttpClientService&lt;TResult&gt; : IDisposable where TResult : class
{
    private HttpClient client = new HttpClient();
    public HttpClientService(string baseUrl)
    {
        client.BaseAddress = new Uri(baseUrl);
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.Timeout = new TimeSpan(0, 30, 0);
    }
    public TResult GetAPI(string url, Dictionary&lt;string,string&gt; urlParameters = null, Dictionary&lt;string, string&gt; headers = null)
    {
        string parameters = string.Empty;

        if (urlParameters != null)
        {
            parameters = BuildURLParametersString(urlParameters);
            url = string.IsNullOrEmpty(parameters) ? url : url + parameters;
        }

        if (headers != null)
        {
            AddHeaders(headers);
        }

        var response = Task.Run(() =&gt; client.GetAsync(url)).Result;
        var apiResult = response.Content.ReadAsStringAsync().Result;
        var result = JsonConvert.DeserializeObject&lt;TResult&gt;(apiResult);
        return result;
    }
    public TResult PostAPI(string url, Dictionary&lt;string, string&gt; formParameters = null, string jsonString = "", Dictionary&lt;string, string&gt; headers = null)
    {
        HttpContent contentPost = null;
        if (headers != null)
        {
            AddHeaders(headers);
        }
        if (formParameters != null)
        {
            var formContent = new FormUrlEncodedContent(formParameters);
            contentPost = formContent;
        }
        else if (!string.IsNullOrEmpty(jsonString))
        {
            var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
            contentPost = content;
        }
        var response = Task.Run(() =&gt; client.PostAsync(url, contentPost)).Result;
        var apiResult = response.Content.ReadAsStringAsync().Result;
        var result = JsonConvert.DeserializeObject&lt;TResult&gt;(apiResult);
        return result;
    }
    private String BuildURLParametersString(Dictionary&lt;string, string&gt; parameters)
    {
        UriBuilder uriBuilder = new UriBuilder();
        var query = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query);
        foreach (var urlParameter in parameters)
        {
            query[urlParameter.Key] = urlParameter.Value;
        }
        uriBuilder.Query = query.ToString();
        return uriBuilder.Query;
    }
    private void AddHeaders(Dictionary&lt;string, string&gt; headers)
    {
        foreach (var header in headers)
        {
            if (!string.IsNullOrEmpty(header.Value))
            {
                client.DefaultRequestHeaders.Add(header.Key, header.Value);
            }
        }
    }
    public void Dispose()
    {
        client.Dispose();
    }
}


and from my application used like below

using (var clientService = new HttpClientService&lt;GeoCodeResponse&gt;("https://maps.googleapis.com"))
{
         var param = new Dictionary&lt;string, string&gt;();
         param.Add("latlng", $"{latitude},{longitude}");
         param.Add("result_type", "locality");
         param.Add("key", GoogleApiKey);

         var apiResult = clientService.GetAPI("maps/api/geocode/json", param);   
}


please suggest me what i am implemented is currect or any better improvement for code any changes.
A few points that come to mind:


A lot of your code closely follows the underlying API of the HTTP client instance. It would be better to have a function that generates your client with its default settings (the ones you're setting in the constructor), then just use the appropriate methods on the HttpClient.
There arent many (any?) good use cases for calling Result on a task. You should make your method async and await the task instead.
Your use of Task.Run is redundant. You're wrapping one task inside another.
What happens if there is an error? Incorrect URI, no network etc...