예제 #1
0
        /// <summary>
        /// Generic Method to perform an HTTP GET Request
        /// </summary>
        public async Task <ApiHttpResponse <T> > GetDataAsync <T>(string Url, string jwt = null)
        {
            // Get a new http client object from the factory
            var httpClient = _httpClientFactory.CreateClient();

            // Add Token to Header if present
            if (!string.IsNullOrWhiteSpace(jwt))
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt);
            }

            // Call the API
            var response = await httpClient.GetAsync(new Uri(Url));

            string jsonString = await response.Content.ReadAsStringAsync();

            // Create the return object
            var apiResponse = new ApiHttpResponse <T>()
            {
                StatusCode = response.StatusCode, ReasonPhrase = response.ReasonPhrase
            };

            if (response.IsSuccessStatusCode)
            {
                apiResponse.ApiData = _jsonService.FromJson <T>(jsonString);
            }
            else
            {
                apiResponse.ErrorApiResponse = _jsonService.FromJson <ApiResponse>(jsonString);
            }

            return(apiResponse);
        }
예제 #2
0
 private FeatureFlagSettings Decode(byte[] value)
 {
     return(_jsonService.FromJson(Encoding.UTF8.GetString(value)));
 }
 private User Decode(byte[] value)
 {
     return(_jsonService.FromJson(Encoding.UTF8.GetString(value)));
 }
예제 #4
0
 private ApplicationSettings Decode(byte[] value)
 {
     return(_jsonService.FromJson(Encoding.UTF8.GetString(value)));
 }