Typed abstract httpClient for IHttpClientFactory. Contains Sync/Async methods for creating requests. Also contains basic
-
Create your own typed httpClient
public class TestClient : AbstractHttpClient { public TestClient(HttpClient httpClient, ILogger<TestClient> logger) : base(httpClient, logger) { } public ResultMessage<Answer[]> Get() { return SyncGet<Answer[]>("Catalogs/users", new Dictionary<string, string>(){ {"name", "Вася"} }); } public async Task<ResultMessage<Answer[]>> GetAsync() { return await AsyncGet<Answer[]>("Catalogs/users", new Dictionary<string, string>(){ {"name", "Вася"} }); } }
-
In
Startup.cs
in methodvoid AddServices(IServiceCollection services)
add your client to serviceCollection Factory:services.AddSaltHttpClient<TestClient>(baseUrl);