26 lines
603 B
C#
26 lines
603 B
C#
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;
|
|
}
|
|
|
|
}
|
|
}
|