{"id":15101862,"url":"https://github.com/owen-krueger/http.resilience.default","last_synced_at":"2025-04-05T09:14:16.257Z","repository":{"id":244803043,"uuid":"816312258","full_name":"Owen-Krueger/Http.Resilience.Default","owner":"Owen-Krueger","description":"Decent defaults for adding resilence to HTTP clients.","archived":false,"fork":false,"pushed_at":"2024-06-17T21:37:57.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T09:14:13.085Z","etag":null,"topics":["csharp","http","httpclient","net8","nuget","resilience","servicecollection"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Owen-Krueger.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-17T13:38:15.000Z","updated_at":"2024-06-18T16:33:52.000Z","dependencies_parsed_at":"2024-06-17T15:23:39.167Z","dependency_job_id":"e81513fa-0e64-429c-828d-14b5aa492a77","html_url":"https://github.com/Owen-Krueger/Http.Resilience.Default","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":0.09999999999999998,"last_synced_commit":"f0d8619dfe7b3eaecad63c54a99d0700ef5b1d6d"},"previous_names":["owen-krueger/http.resilience.default"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Owen-Krueger%2FHttp.Resilience.Default","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Owen-Krueger%2FHttp.Resilience.Default/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Owen-Krueger%2FHttp.Resilience.Default/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Owen-Krueger%2FHttp.Resilience.Default/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Owen-Krueger","download_url":"https://codeload.github.com/Owen-Krueger/Http.Resilience.Default/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312093,"owners_count":20918344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","http","httpclient","net8","nuget","resilience","servicecollection"],"created_at":"2024-09-25T18:42:09.310Z","updated_at":"2025-04-05T09:14:16.233Z","avatar_url":"https://github.com/Owen-Krueger.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Http Resilience Default NuGET Package\n\n[![.NET](https://github.com/Owen-Krueger/Http.Resilience.Default/actions/workflows/dotnet.yaml/badge.svg)](https://github.com/Owen-Krueger/Http.Resilience.Default/actions/workflows/dotnet.yaml)\n\n## Resilience Pipelines\n\nThis package provides a resilience pipeline for HttpClient, with sensible defaults. The pipeline created can be used as is or configured further.\n\nBy default, pipelines are created with the following policies:\n- HTTP requests will be retried if the following exceptions are thrown:\n  - TaskCanceledException\n  - TimeoutRejectedException\n- HTTP requests will be retried if the response status code is any that don't fall within the 200-299 or 400-499 ranges.\n- Requests will be timed out after 30 seconds.\n- Requests will be retried twice (three total times).\n- Requests will be delayed by two seconds between retries.\n- Retries will be exponentially backed off.\n- Retries will utilize jitters, which will slightly randomize the delay between retries.\n\nTo set up a resilience pipeline, use the following code:\n\n``` C#\nvar pipelineBuilder = HttpResilience.GetResiliencePipelineBuilder();\nvar pipeline = pipelineBuilder.Build();\n```\n\nRetry configuration or timeouts can be configured:\n``` C#\n// Default options.\nvar pipeLineBuilder = HttpResilience.GetResiliencePipelineBuilder();\n\n// Pipeline key specified\nvar pipelineBuilder = HttpResilience.GetResiliencePipelineBuilder(\"my_resilience_pipeline\");\n\n// Retry configured.\nvar pipelineBuilder = HttpResilience.GetResiliencePipelineBuilder(x =\u003e\n{\n    x.Delay = TimeSpan.FromSeconds(5);\n    x.BackoffType = BackoffType.Linear;\n});\n\n// Timeout configured.\nvar pipelineBuilder = HttpResilience.GetResiliencePipelineBuilder(TimeSpan.FromSeconds(10));\n\n// Retry and timeout configured.\nvar pipelineBuilder = HttpResilience.GetResiliencePipelineBuilder(x =\u003e\n{\n    x.Delay = TimeSpan.FromSeconds(5);\n    x.BackoffType = BackoffType.Linear;\n}, TimeSpan.FromSeconds(10));\n\n// Key, retry, and timeout configured.\nvar pipelineBuilder = HttpResilience.GetResiliencePipelineBuilder(\"my_resilience_pipeline\", x =\u003e\n{\n    x.Delay = TimeSpan.FromSeconds(5);\n    x.BackoffType = BackoffType.Linear;\n}, TimeSpan.FromSeconds(10));\n```\n\nWhen using these methods, you're expected to manage the pipeline and HttpClients yourself. This package also provides extensions for `IServiceCollection` and `IHttpClientBuilder` to make it easier to set up and use resilience pipelines.\n\nUnless specified, the pipeline will use the key `default_resilience_pipeline`.\n\n## IServiceCollection Extensions\n\nThis package provides a `AddHttpResiliencePipeline` extension method for `IServiceCollection` that will add a resilience pipeline to the service collection. This sets up the pipeline similar to the example above, but allows you to dependency inject the pipeline into other services.\n\nThis method can be used as follows:\n\n``` C#\n// Default options.\nservices.AddHttpResiliencePipeline();\n\n// Pipeline key specified\nservices.AddHttpResiliencePipeline(\"my_resilience_pipeline\");\n\n// Retry configured.\nservices.AddHttpResiliencePipeline(x =\u003e\n{\n    x.Delay = TimeSpan.FromSeconds(5);\n    x.BackoffType = BackoffType.Linear;\n});\n\n// Timeout configured.\nservices.AddHttpResiliencePipeline(TimeSpan.FromSeconds(10));\n\n// Retry and timeout configured.\nservices.AddHttpResiliencePipeline(x =\u003e\n{\n    x.Delay = TimeSpan.FromSeconds(5);\n    x.BackoffType = BackoffType.Linear;\n}, TimeSpan.FromSeconds(10));\n\n// Key, retry, and timeout configured.\nservices.AddHttpResiliencePipeline(\"my_resilience_pipeline\", x =\u003e\n{\n    x.Delay = TimeSpan.FromSeconds(5);\n    x.BackoffType = BackoffType.Linear;\n}, TimeSpan.FromSeconds(10));\n```\n\nUnless specified, the pipeline will use the key `default_resilience_pipeline`. This key can be used to retrieve the pipeline from the service collection.\n\nConsuming the pipeline in a service can be done as follows:\n\n``` C#\nResiliencePipeline pipelineProvider = serviceProvider.GetRequiredService\u003cResiliencePipeline\u003cstring\u003e\u003e();\nvar pipeline = provider.GetPipeline(HttpResilienceConstants.DefaultPipelineKey);\n```\n\n## IHttpClientBuilder Extensions\n\nThis package provides a `AddHttpResilienceHandler` extension method for `IHttpClientBuilder` that will add a resilience pipeline to the service collection. This sets up the pipeline similar to the example above, but allows you to dependency inject the pipeline into other services.\n\nThis method can be used as follows:\n\n``` C#\nconst string clientName = \"my_client\";\n\n// Default options.\nservices.AddHttpClient(ClientKey)\n  .AddHttpResilienceHandler();\n\n// Pipeline key specified\nservices.AddHttpClient(ClientKey)\n  .AddHttpResilienceHandler(\"my_resilience_pipeline\");\n\n// Retry configured.\nservices.AddHttpClient(ClientKey)\n  .AddHttpResilienceHandler(x =\u003e\n{\n    x.Delay = TimeSpan.FromSeconds(5);\n    x.BackoffType = BackoffType.Linear;\n});\n\n// Timeout configured.\nservices.AddHttpClient(ClientKey)\n  .AddHttpResilienceHandler(TimeSpan.FromSeconds(10));\n\n// Retry and timeout configured.\nservices.AddHttpClient(ClientKey)\n  .AddHttpResilienceHandler(x =\u003e\n{\n    x.Delay = TimeSpan.FromSeconds(5);\n    x.BackoffType = BackoffType.Linear;\n}, TimeSpan.FromSeconds(10));\n\n// Key, retry, and timeout configured.\nservices.AddHttpClient(ClientKey)\n  .AddHttpResilienceHandler(\"my_resilience_pipeline\", x =\u003e\n{\n    x.Delay = TimeSpan.FromSeconds(5);\n    x.BackoffType = BackoffType.Linear;\n}, TimeSpan.FromSeconds(10));\n```\n\nUnless specified, the pipeline will use the key `default_resilience_pipeline`. This key is used internally within the `HttpClient`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowen-krueger%2Fhttp.resilience.default","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fowen-krueger%2Fhttp.resilience.default","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowen-krueger%2Fhttp.resilience.default/lists"}