ApiService.cs 614 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Http;
  5. using System.Net.Http.Json;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace AvaloniaApplication1.Models
  9. {
  10. public class ApiService
  11. {
  12. private readonly HttpClient _httpClient;
  13. public ApiService()
  14. {
  15. _httpClient = new HttpClient();
  16. _httpClient.BaseAddress = new Uri("https://localhost:7241/");
  17. }
  18. public async Task<T?> GetAsync<T>(string endpint)
  19. {
  20. return await _httpClient.GetFromJsonAsync<T>(endpint);
  21. }
  22. }
  23. }