Lesson 10 - Displaying Json

This commit is contained in:
2025-08-09 09:14:32 +02:00
parent 017aae6782
commit fd2e74e658
3 changed files with 54 additions and 9 deletions

25
SpectreDemos/Helpers.cs Normal file
View File

@ -0,0 +1,25 @@
using Spectre.Console;
namespace SpectreDemos;
public static class Helpers
{
public static async Task<string> FetchApiDataAsync(string apiUrl)
{
using var client = new HttpClient();
try
{
HttpResponseMessage response = await client.GetAsync(apiUrl);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
AnsiConsole.MarkupLine($"[red]Error fetching data from API:[/]{ex.Message}");
return string.Empty;
}
}
}