public async Task <NewsDoc[]> GetAll() { // In order to make it work you need to get a new key from The New York Times API: https://developer.nytimes.com/ string url = "https://api.nytimes.com/svc/search/v2/articlesearch.json?api-key=000000000000000000"; var client = new HttpClient(); var newsData = await client.GetAsync(url); var news = await newsData.Content.ReadAsStringAsync(); var messages = JsonConvert.DeserializeObject <NewsRoot>(news); _messagesInMemory = messages; return(messages.response.docs); }
public async Task <NewsRoot> GetAsync() { NewsRoot newsRoot = null; try { var response = await httpClient.GetAsync("v2/top-headlines?country=us&apiKey=9034101789784cea94358866ce8a262e"); var responseBody = await response.Content.ReadAsStringAsync(); newsRoot = JsonConvert.DeserializeObject <NewsRoot>(responseBody); } catch (Exception e) { _logger.LogError(e, e.Message); } return(newsRoot); }