Pdsr.Http 4.0.0-beta.1

This is a prerelease version of Pdsr.Http.
dotnet add package Pdsr.Http --version 4.0.0-beta.1
                    
NuGet\Install-Package Pdsr.Http -Version 4.0.0-beta.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pdsr.Http" Version="4.0.0-beta.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pdsr.Http" Version="4.0.0-beta.1" />
                    
Directory.Packages.props
<PackageReference Include="Pdsr.Http" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pdsr.Http --version 4.0.0-beta.1
                    
#r "nuget: Pdsr.Http, 4.0.0-beta.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Pdsr.Http@4.0.0-beta.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pdsr.Http&version=4.0.0-beta.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Pdsr.Http&version=4.0.0-beta.1&prerelease
                    
Install as a Cake Tool

Pdsr HttpClient Helper

A helper library to use with HTTP API Calls

.NET

NuGet version (Pdsr.Http)

Upgrading from 3.x? See UPGRADING.md for breaking changes in 4.0.

Getting Started

  1. Install the package: dotnet add package Pdsr.Http. The fluent extensions are included; Pdsr.Http.Extensions is no longer needed.
  2. Inherit the abstract class PdsrClientBase and implement SetBaseAddress and SetAuthorizationHeader.
  3. 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> returns default for a non-success response or an empty body. Call .EnsureSuccess() to throw HttpRequestException on a non-success status instead.
  • GetString and GetStream return the raw response contents.
  • Override WriteLog to log every response in one place, and IsRetryRequired to retry responses (up to _retryCount times 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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