demo/Services/ProfileService.cs

33 lines
892 B
C#
Raw Permalink Normal View History

2024-06-21 16:48:24 +08:00
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using antblazorpro.Models;
namespace antblazorpro.Services
{
public interface IProfileService
{
Task<BasicProfileDataType> GetBasicAsync();
Task<AdvancedProfileData> GetAdvancedAsync();
}
public class ProfileService : IProfileService
{
private readonly HttpClient _httpClient;
public ProfileService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<BasicProfileDataType> GetBasicAsync()
{
return await _httpClient.GetFromJsonAsync<BasicProfileDataType>("data/basic.json");
}
public async Task<AdvancedProfileData> GetAdvancedAsync()
{
return await _httpClient.GetFromJsonAsync<AdvancedProfileData>("data/advanced.json");
}
}
}