public void Run() { string content; string url = "https://some-random-api.ml/facts/panda"; using (var wc = new WebClient()) { content = wc.DownloadString(url); } PandaFactModel pandaFact = JsonSerializer.Deserialize <PandaFactModel>(content); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(pandaFact.Fact); Console.WriteLine(); }
private static void RandomFoxFact() { logger.LogInformation($"User Choice : {nameof(RandomFoxFact)}"); string content; string url = "https://some-random-api.ml/facts/fox"; using (var wc = new WebClient()) { content = wc.DownloadString(url); } PandaFactModel foxFact = JsonSerializer.Deserialize <PandaFactModel>(content); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(foxFact.Fact); Console.WriteLine(); }