private async Task GetCharacters() { await _characterService.Clean(); var client = _clientFactory.CreateClient(); client.BaseAddress = new Uri("https://rickandmortyapi.com/"); string next = "api/character/?status=alive"; int currentPage = 0; while (string.IsNullOrEmpty(next) == false) { currentPage++; var request = new HttpRequestMessage(HttpMethod.Get, next); var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { var info = await ReadAndSave(response); next = string.IsNullOrEmpty(info.Next) ? string.Empty : new Uri(info.Next).PathAndQuery; _logger.LogInformation("Retrieved page {0} of {1}", currentPage, info.Pages); } else { _logger.LogWarning("Unable to retrieve character data. Status code was {0}.", response.StatusCode); } } _logger.LogInformation("FINISHED >> Total characters in database: {0}.", await _characterService.CountAsync()); }