Fluent.Unions.Refit
1.1.0
dotnet add package Fluent.Unions.Refit --version 1.1.0
NuGet\Install-Package Fluent.Unions.Refit -Version 1.1.0
<PackageReference Include="Fluent.Unions.Refit" Version="1.1.0" />
<PackageVersion Include="Fluent.Unions.Refit" Version="1.1.0" />
<PackageReference Include="Fluent.Unions.Refit" />
paket add Fluent.Unions.Refit --version 1.1.0
#r "nuget: Fluent.Unions.Refit, 1.1.0"
#:package Fluent.Unions.Refit@1.1.0
#addin nuget:?package=Fluent.Unions.Refit&version=1.1.0
#tool nuget:?package=Fluent.Unions.Refit&version=1.1.0
![]()
Fluent.Unions.Refit
Converts Refit API responses to Result, Result<T> and Result<Option<T>>, so an HTTP error or a network failure becomes an error instead of an exception. It builds on Fluent.Unions and Refit (MIT), and works with the source-generated Refit clients, so it is trim and Native AOT safe.
Installation
dotnet add package Fluent.Unions.Refit
Usage
Declare the Refit method with IApiResponse<T>, which never throws for an HTTP error, and convert the call.
using Refit;
using Fluent.Unions.Refit;
public interface IUserApi
{
[Get("/users/{id}")]
Task<IApiResponse<User>> GetUser(int id, CancellationToken cancellationToken = default);
[Delete("/users/{id}")]
Task<IApiResponse> DeleteUser(int id, CancellationToken cancellationToken = default);
}
Result<User> user = await api.GetUser(7).ToResult();
// the user, or an ApiException (HTTP error) or an ApiRequestException (network failure) as the error
Result<Option<User>> maybe = await api.GetUser(7).ToOptionalResult();
// none for a 404, the user for a 2xx, an error for anything else
Result deleted = await api.DeleteUser(7).ToResult();
Cancellation and timeouts are thrown, never turned into an error. Task<ApiResponse<T>> works the same way, and ToResult() and ToOptionalResult() convert a response you already hold.
With your own result type
ToResult() and ToOptionalResult() produce the default Fluent.Unions.Result<T>. To get your own type, wrap the call in your own Result.TryAsync(...), or convert with Match. See your own result type.
Shop.Result<User> mine = user.Match(value => (Shop.Result<User>)value, error => DomainException.FromException(error));
Documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Fluent.Unions (>= 1.1.0)
- Refit (>= 17.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.