HttpResultMonad.HttpResultOnHttpClient by Eduardo Serrano

<PackageReference Include="HttpResultMonad.HttpResultOnHttpClient" Version="1.0.1" />

 HttpResultClient

public class HttpResultClient : IDisposable
using HttpResultMonad.State; using System; using System.Net.Http; using System.Threading; using System.Threading.Tasks; namespace HttpResultMonad.HttpResultOnHttpClient { public class HttpResultClient : IDisposable { protected HttpClient HttpClient { get; } public HttpResultClient(HttpClient httpClient) { if (httpClient == null) throw new ArgumentNullException("httpClient"); HttpClient = httpClient; } public async Task<HttpResult> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken)) { HttpResponseMessage obj = await HttpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); IHttpState val = new HttpClientState(obj); return obj.IsSuccessStatusCode ? HttpResult.Ok(val) : HttpResult.Fail(val); } public void Dispose() { HttpClient.Dispose(); } } }