Created
March 26, 2017 22:13
-
-
Save CESARDELATORRE/d80c6423a1aebaffaf387469f5194f5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<Catalog> GetCatalogItems(int page,int take, int? brand, int? type) | |
{ | |
_apiClient = new HttpClient(); | |
var itemsQs = $"items?pageIndex={page}&pageSize={take}"; | |
var filterQs = ""; | |
if (brand.HasValue || type.HasValue) | |
{ | |
var brandQs = (brand.HasValue) ? brand.Value.ToString() : "null"; | |
var typeQs = (type.HasValue) ? type.Value.ToString() : "null"; | |
filterQs = $"/type/{typeQs}/brand/{brandQs}"; | |
} | |
var catalogUrl = $"{_remoteServiceBaseUrl}items{filterQs}?pageIndex={page}&pageSize={take}"; | |
var dataString = ""; | |
// | |
// Using HttpClient with Retry and Exponential Backoff | |
// | |
var retry = new RetryWithExponentialBackoff(); | |
await retry.RunAsync(async () => | |
{ | |
// work with HttpClient call | |
dataString = await _apiClient.GetStringAsync(catalogUrl); | |
}); | |
//var dataString = await _apiClient.GetStringAsync(catalogUrl); | |
var response = JsonConvert.DeserializeObject<Catalog>(dataString); | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can this code be implemented for synchronous method?