WhateverDotNet.API.Abstractions 0.1.0-preview.6

This is a prerelease version of WhateverDotNet.API.Abstractions.
dotnet add package WhateverDotNet.API.Abstractions --version 0.1.0-preview.6
                    
NuGet\Install-Package WhateverDotNet.API.Abstractions -Version 0.1.0-preview.6
                    
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="WhateverDotNet.API.Abstractions" Version="0.1.0-preview.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WhateverDotNet.API.Abstractions" Version="0.1.0-preview.6" />
                    
Directory.Packages.props
<PackageReference Include="WhateverDotNet.API.Abstractions" />
                    
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 WhateverDotNet.API.Abstractions --version 0.1.0-preview.6
                    
#r "nuget: WhateverDotNet.API.Abstractions, 0.1.0-preview.6"
                    
#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 WhateverDotNet.API.Abstractions@0.1.0-preview.6
                    
#: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=WhateverDotNet.API.Abstractions&version=0.1.0-preview.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=WhateverDotNet.API.Abstractions&version=0.1.0-preview.6&prerelease
                    
Install as a Cake Tool

WhateverDotNet.API.Abstractions

Abstractions and helpers for building JSON-based REST API clients, including:

  • BaseJsonRestClient: reusable base class for sending JSON requests and deserializing JSON responses
  • RequestSent / ResponseReceived events for custom API-call logging
  • DI helpers to register logging utilities
  • Test-execution logging abstractions (useful for NUnit / BDD-style step output)

Install

dotnet add package WhateverDotNet.API.Abstractions --prerelease

What's inside

  • Base client: WhateverDotNet.API.Abstractions.BaseJsonRestClient
    • Sends requests via an initialized HttpClient
    • Serializes request bodies to JSON and deserializes responses from JSON
    • Raises RequestSent and ResponseReceived events for custom logging hooks
    • Optional structured tracing via ILogger<BaseJsonRestClient>
  • Options: BaseJsonRestClientOptions (BaseUrl, Timeout)
  • Events: CustomApiCallLoggerEventArgs (caller method, HTTP method, endpoint path, serialized payload)
  • Logging:
    • ITestExecutionLogger (test output abstraction)
    • NUnitTestExecutionLogger (writes to Console)
    • ILogMessageFormatter / ApiLogMessageFormatter (human-readable step messages)
  • DI: ServiceCollectionExtensions
    • AddApiLogMessageFormatter()
    • AddNUnitTestExecutionLogger(options)
  • Exceptions: HttpClientNotInitializedException

Basic usage

Create your API client by inheriting from BaseJsonRestClient, call CreateClient to initialize the HttpClient, then use the Try*AsJsonAsync helpers.

using System.Net;

using FluentAssertions;

using Microsoft.Extensions.Logging;

using WhateverDotNet.API.Abstractions;
using WhateverDotNet.API.Abstractions.Logging;

public sealed class MyApiClient : BaseJsonRestClient
{
    public MyApiClient(
        BaseJsonRestClientOptions options,
        ILogMessageFormatter formatter,
        ITestExecutionLogger? testExecutionLogger,
        ILoggerFactory? loggerFactory = null)
        : base(options, loggerFactory)
    {
        if (testExecutionLogger is not null)
        {
            RequestSent += (_, args) =>
                testExecutionLogger.LogStep(
                    formatter.FormatLogMessage(
                        args.ClientMethodName,
                        args.HttpMethod,
                        args.EndpointPath,
                        args.SerializedPayload));
        }
    }

    public void ConnectAs(string bearerToken)
    {
        // The base class throws if BaseUrl/token are missing.
        CreateClient($"Bearer {bearerToken}");
    }

    public async Task<MyDto> GetSomethingAsync(CancellationToken cancellationToken = default)
    {
        (MyDto? response, HttpResponseMessage message) =
            await TryGetAsJsonAsync<MyDto>("/v1/something", cancellationToken: cancellationToken);

        message.StatusCode.Should().Be(HttpStatusCode.OK);
        response.Should().NotBeNull();

        return response!;
    }
}

public sealed record MyDto(string Id);

DI registration (optional)

using Microsoft.Extensions.DependencyInjection;

using WhateverDotNet.API.Abstractions.Extensions;
using WhateverDotNet.API.Abstractions.Logging;

var services = new ServiceCollection();

services.AddApiLogMessageFormatter();
services.AddNUnitTestExecutionLogger(new TestExecutionLoggerOptions
{
    StepPattern = "STEP: {0}",
    PreconditionPattern = "PRE: {0}",
    ExpectedResultPattern = "EXP: {0}",
    ActualResultPattern = "ACT: {0}",
});

Notes

  • BaseJsonRestClient expects _httpClient to be initialized (for example via CreateClient(...)). If it isn't, calls throw HttpClientNotInitializedException.
  • API-call logging is opt-in: subscribe to RequestSent / ResponseReceived and wire your own ITestExecutionLogger, telemetry, or other handlers.
  • The default JSON serializer options use camelCase naming and are case-insensitive on property names.

Release notes

0.1.0-preview.6

  • Breaking change: BaseJsonRestClient no longer accepts ILogMessageFormatter / ITestExecutionLogger in its constructor. Use the RequestSent and ResponseReceived events instead.
  • Added CustomApiCallLoggerEventArgs and RequestSent / ResponseReceived events for extensible API-call logging.
  • Added TryPostAsJsonAsync<TResponse> overload without a request body.
  • CreateClient now throws ArgumentException (instead of ArgumentNullException) for blank tokens or missing base URLs.
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-preview.6 76 6/7/2026
0.1.0-preview.5 58 5/5/2026
0.1.0-preview.4 71 3/31/2026
0.1.0-preview.3 62 3/20/2026
0.1.0-preview.2 65 3/20/2026
0.1.0-preview.1 67 3/18/2026

Breaking: BaseJsonRestClient constructor no longer requires ILogMessageFormatter/ITestExecutionLogger; subscribe to RequestSent/ResponseReceived instead. Added CustomApiCallLoggerEventArgs, TryPostAsJsonAsync overload without body, and ArgumentException validation in CreateClient.