A robust .NET library that enhances Refit clients with resilience policies using Polly and Simmy.
$ dotnet add package ResilientRefitResilientRefit.Core is a library designed to enhance the resilience of Refit clients by integrating Polly policies. This library allows you to configure Refit clients with retry, circuit breaker, and timeout policies, ensuring that your HTTP requests are more robust and fault-tolerant.
To install ResilientRefit.Core, add the following NuGet package to your project:
Configure your resiliency policies and Refit client settings in your appsettings.json file:
"HttpBin": {
"BaseUrl": "https://httpbin.org",
"ResiliencyPolicies": {
"RetryPolicy": {
"Count": 3,
"Delay": 2,
"Jitter": 1000
},
"CircuitBreakerPolicy": {
"Count": 5,
"Duration": 5
},
"TimeoutPolicy": {
"Duration": 10
}
}
},
Create an interface for your Refit client: Renders as:
public interface IMyRefitClient { [Get("/endpoint")] Task<ApiResponse> GetEndpointAsync(); }
PollyPoliciesExtensionsConfigureRefitClient<TClient>Configures a Refit client with Polly policies.
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
+ services.ConfigureRefitClient<IMyRefitClient>(configuration, "MyRefitClient");
}
}
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any changes.
If you have any questions, suggestions, or would like to contribute to this project, feel free to reach out!
You can also open an issue on GitHub Issues if you encounter any problems or have feature requests.