Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fs
hangfire
httpclient
httpclientfactory
ietf
interop
jetbrains
jitter
Expand All @@ -46,6 +47,8 @@ pluralsight
pollydocs
pre
rabbitmq
ratelimit
ratelimitheaders
ratelimiting
ratiosd
readme
Expand Down
37 changes: 37 additions & 0 deletions docs/community/http-client-integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,41 @@ Here we create a strategy which will retry the HTTP request if the status code i

The `HandleTransientHttpError` method is equivalent to the [`HttpPolicyExtensions.HandleTransientHttpError`](https://github.com/App-vNext/Polly.Extensions.Http/blob/93b91c4359f436bda37f870c4453f25555b9bfd8/src/Polly.Extensions.Http/HttpPolicyExtensions.cs) method in the [App-vNext/Polly.Extensions.Http](https://github.com/App-vNext/Polly.Extensions.Http) repository.

### Optional: Auto-throttling with RateLimitHeaders

[RateLimitHeaders][ratelimitheaders] is a library that parses [IETF RateLimit headers](https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/) and can proactively throttle requests to avoid HTTP 429 errors before they happen. It provides a [Polly.Core integration package][ratelimitheaders.polly] that you can add to any of the pipelines below:

```cs
builder.AddRateLimitHeaders(options =>
{
options.EnableProactiveThrottling = true;
});
```

> [!TIP]
> The order of strategies in your pipeline matters. Place rate limit handling before retry strategies so that proactive throttling occurs before any retry attempts.

For example, adding it to the `HttpClient` sample:

```cs
services.AddHttpClient(HttpClientName)
.ConfigureHttpClient(client => client.BaseAddress = BaseAddress)
.AddResilienceHandler("ratelimit_aware_pipeline", builder =>
{
builder.AddRateLimitHeaders(options => options.EnableProactiveThrottling = true);
builder.AddRetry(GetRetryOptions());
});
```

> [!NOTE]
> The [RateLimitHeaders.Polly][ratelimitheaders.polly] package is required for the `AddRateLimitHeaders` extension.

#### Further reading for RateLimitHeaders

- [RateLimitHeaders on GitHub][ratelimitheaders]
- [Polly.Core integration documentation](https://alos.no/ratelimitheaders/articles/polly-integration.html)
- [Preparing for the IETF RateLimit header standard in .NET](https://dev.to/alexisfranorge/preparing-for-the-ietf-ratelimit-header-standard-in-net-3ebk)

## With HttpClient

We use the [`AddResilienceHandler`](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.resiliencehttpclientbuilderextensions.addresiliencehandler) method to register our resilience strategy with the built-in [`HttpClient`](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient).
Expand Down Expand Up @@ -204,4 +239,6 @@ var response = await restClient.ExecuteAsync(request);
[flurl]: https://flurl.dev/
[m.e.dependencyinjection]: https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection
[m.e.http.resilience]: https://www.nuget.org/packages/Microsoft.Extensions.Http.Resilience
[ratelimitheaders]: https://github.com/Alos-no/RateLimitHeaders
[ratelimitheaders.polly]: https://www.nuget.org/packages/RateLimitHeaders.Polly
[restsharp]: https://restsharp.dev/
1 change: 1 addition & 0 deletions docs/community/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This includes Blogs, podcasts, courses, e-books, architecture samples and videos
- [Building resilient cloud services with .NET 8](https://devblogs.microsoft.com/dotnet/building-resilient-cloud-services-with-dotnet-8/) by [Martin Tomka](https://github.com/martintmk)
- [Resilience and chaos engineering](https://devblogs.microsoft.com/dotnet/resilience-and-chaos-engineering/) by [Martin Tomka](https://github.com/martintmk)
- [Securing the supply chain at scale - Starting with 71 important open source projects](https://github.blog/open-source/maintainers/securing-the-supply-chain-at-scale-starting-with-71-important-open-source-projects/) by [Gregg Cochran](https://github.com/dubsopenhub)
- [Preparing for the IETF RateLimit header standard in .NET](https://dev.to/alexisfranorge/preparing-for-the-ietf-ratelimit-header-standard-in-net-3ebk) - by [Alexis Pujo](https://github.com/Alexis-)

## Podcasts

Expand Down