using System.Net.Http.Json; // GetFromJsonAsync, ReadFromJsonAsync using Packt.Shared; // Customer namespace Northwind.BlazorWasm.Client.Data; public class NorthwindService : INorthwindService { private readonly HttpClient http; public NorthwindService(HttpClient http) { this.http = http; } public Task> GetCustomersAsync() { return http.GetFromJsonAsync >("api/customers")!; } public Task> GetCustomersAsync(string country) { return http.GetFromJsonAsync >($"api/customers/in/{country}")!; } public Task GetCustomerAsync(string id) { return http.GetFromJsonAsync ($"api/customers/{id}"); } public async Task CreateCustomerAsync(Customer c) { HttpResponseMessage response = await http.PostAsJsonAsync("api/customers", c); return (await response.Content .ReadFromJsonAsync())!; } public async Task UpdateCustomerAsync(Customer c) { HttpResponseMessage response = await http.PutAsJsonAsync("api/customers", c); return (await response.Content .ReadFromJsonAsync())!; } public async Task DeleteCustomerAsync(string id) { HttpResponseMessage response = await http.DeleteAsync($"api/customers/{id}"); } }