ResilientRefit 1.0.2
Use Policybuilder.NET instead.
See the version list below for details.
dotnet add package ResilientRefit --version 1.0.2
NuGet\Install-Package ResilientRefit -Version 1.0.2
<PackageReference Include="ResilientRefit" Version="1.0.2" />
paket add ResilientRefit --version 1.0.2
#r "nuget: ResilientRefit, 1.0.2"
// Install ResilientRefit as a Cake Addin #addin nuget:?package=ResilientRefit&version=1.0.2 // Install ResilientRefit as a Cake Tool #tool nuget:?package=ResilientRefit&version=1.0.2
ResilientRefit.Core
Overview
ResilientRefit.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.
Features
- Retry Policy: Automatically retries failed requests a specified number of times with a delay between each attempt.
- Circuit Breaker Policy: Monitors the number of consecutive failures and opens the circuit if the threshold is reached, preventing further requests for a specified duration.
- Timeout Policy: Enforces a maximum duration for each request, ensuring that long-running requests are terminated.
Installation
To install ResilientRefit.Core
, add the following NuGet package to your project:
Configuration
appsettings.json
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
}
}
},
Example Usage
1. Define Your Refit Interface
Create an interface for your Refit client: Renders as:
public interface IMyRefitClient { [Get("/endpoint")] Task<ApiResponse> GetEndpointAsync(); }
API Reference
PollyPoliciesExtensions
ConfigureRefitClient<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");
}
}
- TClient: The type of the Refit client.
- services: The service collection.
- configuration: The configuration.
- sectionName: The configuration section name.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any changes.
Contact
If you have any questions, suggestions, or would like to contribute to this project, feel free to reach out!
- Email: zameer.kh@gmail.com
- GitHub: @zameerkh
You can also open an issue on GitHub Issues if you encounter any problems or have feature requests.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Http.Polly (>= 8.0.8)
- Polly (>= 8.4.2)
- Polly.Extensions (>= 8.4.2)
- Refit (>= 7.2.1)
- Refit.HttpClientFactory (>= 7.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.