Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soenneker/soenneker.extensions.httpclient
A collection of helpful HttpClient extension methods, like retry and auto (de)serialization
https://github.com/soenneker/soenneker.extensions.httpclient
client csharp dotnet extension extensions http httpclient httpclientextension polly retry
Last synced: 13 days ago
JSON representation
A collection of helpful HttpClient extension methods, like retry and auto (de)serialization
- Host: GitHub
- URL: https://github.com/soenneker/soenneker.extensions.httpclient
- Owner: soenneker
- License: mit
- Created: 2024-04-07T17:35:43.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-10-29T09:43:34.000Z (3 months ago)
- Last Synced: 2024-10-29T11:47:00.127Z (3 months ago)
- Topics: client, csharp, dotnet, extension, extensions, http, httpclient, httpclientextension, polly, retry
- Language: C#
- Homepage: https://soenneker.com
- Size: 1.58 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[![](https://img.shields.io/nuget/v/soenneker.extensions.httpclient.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.extensions.httpclient/)
[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.extensions.httpclient/publish-package.yml?style=for-the-badge)](https://github.com/soenneker/soenneker.extensions.httpclient/actions/workflows/publish-package.yml)
[![](https://img.shields.io/nuget/dt/soenneker.extensions.httpclient.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.extensions.httpclient/)# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) Soenneker.Extensions.HttpClient
### A collection of helpful HttpClient extension methods, like retry and auto (de)serialization## Installation
```
dotnet add package Soenneker.Extensions.HttpClient
```### SendToString()
```csharp
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.example.com/data");
var responseContent = await _httpClient.SendToString(request);
```### SendWithError()
```csharp
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.example.com/data");
MySuccessResponse? successResponse, MyErrorResponse? errorResponse = await _httpClient.SendWithError(request);
```### TrySend()
```csharp
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.example.com/data");
bool successful, HttpResponseMessage? response = await _httpClient.TrySend(request);
```### SendWithRetryToType()
```csharp
var requestData = new { Name = "John Doe" };
var response = await _httpClient.SendWithRetryToType(
HttpMethod.Post, // HTTP Method
"https://api.example.com/data", // URI
requestData, // Request body
numberOfRetries: 3, // Retry 3 times
logger: _logger, // Optional logger
baseDelay: TimeSpan.FromSeconds(2), // Exponential backoff
log: true, // Enable logging
cancellationToken: cancellationToken // Cancellation token
);
```... and more