Pdsr.Http
4.0.0-beta.1
dotnet add package Pdsr.Http --version 4.0.0-beta.1
NuGet\Install-Package Pdsr.Http -Version 4.0.0-beta.1
<PackageReference Include="Pdsr.Http" Version="4.0.0-beta.1" />
<PackageVersion Include="Pdsr.Http" Version="4.0.0-beta.1" />
<PackageReference Include="Pdsr.Http" />
paket add Pdsr.Http --version 4.0.0-beta.1
#r "nuget: Pdsr.Http, 4.0.0-beta.1"
#:package Pdsr.Http@4.0.0-beta.1
#addin nuget:?package=Pdsr.Http&version=4.0.0-beta.1&prerelease
#tool nuget:?package=Pdsr.Http&version=4.0.0-beta.1&prerelease
Pdsr HttpClient Helper
A helper library to use with HTTP API Calls
Upgrading from 3.x? See UPGRADING.md for breaking changes in 4.0.
Getting Started
- Install the package:
dotnet add package Pdsr.Http. The fluent extensions are included;Pdsr.Http.Extensionsis no longer needed. - Inherit the abstract class
PdsrClientBaseand implementSetBaseAddressandSetAuthorizationHeader. - Register it as a typed client and configure its
HttpClient.
public interface IOrdersClient : IPdsrClientBase { }
public class OrdersClient : PdsrClientBase, IOrdersClient
{
public OrdersClient(HttpClient client, ILoggerFactory loggerFactory) : base(client, loggerFactory) { }
// HttpClient.BaseAddress cannot change after the first request, so only set it when missing.
protected override Task SetBaseAddress(CancellationToken cancellationToken = default)
{
BaseAddress ??= new Uri("https://example.com/api/");
return Task.CompletedTask;
}
// Called before every attempt, including retries.
protected override Task SetAuthorizationHeader(HttpRequestMessage request, CancellationToken cancellationToken = default)
{
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "...");
return Task.CompletedTask;
}
}
services.AddPdsrClient<IOrdersClient, OrdersClient>(new PdsrClientConfigs { ClientName = "orders" })
.ConfigureHttpClient(c => c.Timeout = TimeSpan.FromSeconds(30));
Then build and send requests fluently:
public class SomeService
{
private readonly IOrdersClient _client;
public SomeService(IOrdersClient client) => _client = client;
public Task<Order?> CreateOrder(string customerId, NewOrder order, CancellationToken cancellationToken = default)
{
return _client.Url("customers").AddUrl(customerId).AddUrl("orders")
.AddQueryString("notify", "true")
.Accept("application/json")
.OnBadRequest<IOrdersClient, ProblemDetails>((problem, response, ct) =>
{
// handle the validation errors
return Task.CompletedTask;
})
.OnNotFound((response, ct) =>
{
// do something when the customer is not found
return Task.CompletedTask;
})
.OnException((response, exception) =>
{
// observe the failure; it is rethrown afterwards
})
.Post(order, SerializationNamingStrategy.Snake)
.SnakeCase()
.SendAsync<Order>(cancellationToken);
}
}
Everything configured on the client (url, query strings, handlers, EnsureSuccess, .SnakeCase()) applies to the next request only, and is reset when it completes, whether it succeeds or fails.
SendAsync<T>returnsdefaultfor a non-success response or an empty body. Call.EnsureSuccess()to throwHttpRequestExceptionon a non-success status instead.GetStringandGetStreamreturn the raw response contents.- Override
WriteLogto log every response in one place, andIsRetryRequiredto retry responses (up to_retryCounttimes per request).
Serialization naming
Responses are deserialized with camelCase names (case-insensitive) by default. Use .SnakeCase() for a single request, or set NamingStrategy in your client's constructor to change the default. Request bodies sent with Post, Put and Patch use the naming strategy passed to them (camelCase by default).
Contribute
Please refer to contribute.
Documents
Under Construction.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Http (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- System.Text.Json (>= 10.0.12)
-
.NETStandard 2.1
- Microsoft.Extensions.Http (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- System.Text.Json (>= 10.0.12)
-
net10.0
- Microsoft.Extensions.Http (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Pdsr.Http:
| Package | Downloads |
|---|---|
|
Pdsr.Http.Extensions
Pdsr HttpClient helper library |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.0-beta.1 | 67 | 10/6/2026 |
| 3.8.1-preview.3 | 321 | 3/17/2025 |
| 3.8.0 | 7,946 | 2/14/2025 |
| 3.7.1 | 4,436 | 9/5/2023 |
| 3.7.0 | 1,840 | 7/19/2023 |
| 3.6.3 | 2,612 | 2/20/2023 |
| 3.6.2 | 1,890 | 2/20/2023 |
| 3.6.1 | 2,166 | 11/11/2022 |
| 3.6.0 | 2,068 | 11/11/2022 |
| 3.5.4 | 2,158 | 8/26/2022 |
| 3.5.3 | 2,162 | 8/26/2022 |
| 3.5.1.445 | 2,616 | 4/17/2022 |
| 3.5.0.443 | 2,210 | 4/17/2022 |
| 3.5.0.442 | 2,239 | 4/17/2022 |