using CartriX.Shared.Models; using Newtonsoft.Json; namespace CartriX.Shared.RequestsToApi { public static class PrinterApiRequest { static readonly HttpClient client = new HttpClient(); public static async Task PrinterByIdAsync(int id) { if (id <= 0) return null; var url = $"http://localhost:5197/api/Printer/{id}"; try { var response = await client.GetAsync(url).ConfigureAwait(false); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); return JsonConvert.DeserializeObject(content); } catch (HttpRequestException e) { Console.WriteLine(e.Message); } catch (JsonException e) { Console.WriteLine($"JSON error: {e.Message}"); } return null; } } }