Пример #1
0
        public async Task <T> GetRequest(string apiPath, ApiSettings apiParam)
        {
            if (apiParam.Id > 0)
            {
                apiPath = apiPath + @"/" + apiParam.ControllerName + @"/" + apiParam.Action + @"/" + apiParam.Id.ToString();
                try
                {
                    var response = await client.GetAsync(apiPath);

                    if (response.IsSuccessStatusCode)
                    {
                        string content = await response.Content.ReadAsStringAsync();

                        T responseObj = ConvertJson.Deserialize <T>(content);
                        return(responseObj);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                apiPath = apiPath + @"/" + apiParam.ControllerName + @"/" + apiParam.Action;
                try
                {
                    var response = await client.GetAsync(apiPath);

                    if (response.IsSuccessStatusCode)
                    {
                        string content = await response.Content.ReadAsStringAsync();

                        T responseObj = ConvertJson.Deserialize <T>(content);
                        return(responseObj);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(default(T));
        }