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
30 changes: 17 additions & 13 deletions docs/community/http-client-integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ The same resilience strategy will be used each time to keep the samples focused

<!-- snippet: http-client-integrations-handle-transient-errors -->
```cs
private static ValueTask<bool> HandleTransientHttpError(Outcome<HttpResponseMessage> outcome) =>
outcome switch
private static ValueTask<bool> HandleTransientHttpError(Outcome<HttpResponseMessage> outcome) => outcome switch
{
{ Exception: HttpRequestException } => PredicateResult.True(),
{ Result.StatusCode: HttpStatusCode.RequestTimeout } => PredicateResult.True(),
Expand Down Expand Up @@ -64,8 +63,8 @@ var response = await httpClient.GetAsync("/408");
> [!NOTE]
> The following packages are required to the above example:
>
> - [Microsoft.Extensions.DependencyInjection](https://www.nuget.org/packages/microsoft.extensions.dependencyinjection): Required for the dependency injection functionality
> - [Microsoft.Extensions.Http.Resilience](https://www.nuget.org/packages/Microsoft.Extensions.Http.Resilience): Required for the `AddResilienceHandler` extension
> - [Microsoft.Extensions.DependencyInjection][m.e.dependencyinjection]: Required for the dependency injection functionality
> - [Microsoft.Extensions.Http.Resilience][m.e.http.resilience]: Required for the `AddResilienceHandler` extension

### Further reading for HttpClient

Expand All @@ -74,7 +73,7 @@ var response = await httpClient.GetAsync("/408");

## With Flurl

[Flurl](https://flurl.dev/) is a URL builder and HTTP client library for .NET.
[Flurl][flurl] is a URL builder and HTTP client library for .NET.

The named `HttpClient` registration and its decoration with our resilience strategy are the same as the built-in `HttpClient`.

Expand Down Expand Up @@ -104,13 +103,13 @@ var response = await flurlClient.Request("/408").GetAsync();
> [!NOTE]
> The following packages are required to the above example:
>
> - [Microsoft.Extensions.DependencyInjection](https://www.nuget.org/packages/microsoft.extensions.dependencyinjection): Required for the dependency injection functionality
> - [Microsoft.Extensions.Http.Resilience](https://www.nuget.org/packages/Microsoft.Extensions.Http.Resilience): Required for the `AddResilienceHandler` extension
> - [Microsoft.Extensions.DependencyInjection][m.e.dependencyinjection]: Required for the dependency injection functionality
> - [Microsoft.Extensions.Http.Resilience][m.e.http.resilience]: Required for the `AddResilienceHandler` extension
> - [Flurl.Http](https://www.nuget.org/packages/Flurl.Http/): Required for the `FlurlClient`

### Further reading for Flurl

- [Flurl home page](https://flurl.dev/)
- [Flurl home page][flurl]

## With Refit

Expand Down Expand Up @@ -152,7 +151,7 @@ var response = await apiClient.GetRequestTimeoutEndpointAsync();
> [!NOTE]
> The following packages are required to the above example:
>
> - [Microsoft.Extensions.DependencyInjection](https://www.nuget.org/packages/microsoft.extensions.dependencyinjection): Required for the dependency injection functionality
> - [Microsoft.Extensions.DependencyInjection][m.e.dependencyinjection]: Required for the dependency injection functionality
> - [Refit.HttpClientFactory](https://www.nuget.org/packages/Refit.HttpClientFactory): Required for the `AddRefitClient` extension

### Further readings for Refit
Expand All @@ -163,7 +162,7 @@ var response = await apiClient.GetRequestTimeoutEndpointAsync();

## With RestSharp

[RestSharp](https://restsharp.dev/) is a simple REST and HTTP API Client for .NET.
[RestSharp][restsharp] is a simple REST and HTTP API Client for .NET.

The named `HttpClient` registration and its decoration with our resilience strategy are the same as the built-in `HttpClient`.

Expand Down Expand Up @@ -194,10 +193,15 @@ var response = await restClient.ExecuteAsync(request);
> [!NOTE]
> The following packages are required to the above example:
>
> - [Microsoft.Extensions.DependencyInjection](https://www.nuget.org/packages/microsoft.extensions.dependencyinjection): Required for the dependency injection functionality
> - [Microsoft.Extensions.Http.Resilience](https://www.nuget.org/packages/Microsoft.Extensions.Http.Resilience): Required for the `AddResilienceHandler` extension
> - [Microsoft.Extensions.DependencyInjection][m.e.dependencyinjection]: Required for the dependency injection functionality
> - [Microsoft.Extensions.Http.Resilience][m.e.http.resilience]: Required for the `AddResilienceHandler` extension
> - [RestSharp](https://www.nuget.org/packages/RestSharp): Required for the `RestClient`, `RestRequest`, `RestResponse`, etc. types

### Further reading for RestSharp

- [RestSharp home page](https://restsharp.dev/)
- [RestSharp home page][restsharp]

[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
[restsharp]: https://restsharp.dev/
3 changes: 1 addition & 2 deletions src/Snippets/Docs/HttpClientIntegrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ internal static class HttpClientIntegrations
private static readonly Uri BaseAddress = new("https://httpstat.us/");

#region http-client-integrations-handle-transient-errors
private static ValueTask<bool> HandleTransientHttpError(Outcome<HttpResponseMessage> outcome) =>
outcome switch
private static ValueTask<bool> HandleTransientHttpError(Outcome<HttpResponseMessage> outcome) => outcome switch
{
{ Exception: HttpRequestException } => PredicateResult.True(),
{ Result.StatusCode: HttpStatusCode.RequestTimeout } => PredicateResult.True(),
Expand Down