ResilientRefit 1.0.3

Suggested Alternatives

PolicyBuilder.NET

Additional Details

Use Policybuilder.NET instead.

dotnet add package ResilientRefit --version 1.0.3                
NuGet\Install-Package ResilientRefit -Version 1.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ResilientRefit" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ResilientRefit --version 1.0.3                
#r "nuget: ResilientRefit, 1.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ResilientRefit as a Cake Addin
#addin nuget:?package=ResilientRefit&version=1.0.3

// Install ResilientRefit as a Cake Tool
#tool nuget:?package=ResilientRefit&version=1.0.3                

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!

You can also open an issue on GitHub Issues if you encounter any problems or have feature requests.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 107 9/28/2024 1.0.3 is deprecated.
1.0.2 97 9/28/2024 1.0.2 is deprecated.