WhateverDotNet.API.Abstractions
0.1.0-preview.6
dotnet add package WhateverDotNet.API.Abstractions --version 0.1.0-preview.6
NuGet\Install-Package WhateverDotNet.API.Abstractions -Version 0.1.0-preview.6
<PackageReference Include="WhateverDotNet.API.Abstractions" Version="0.1.0-preview.6" />
<PackageVersion Include="WhateverDotNet.API.Abstractions" Version="0.1.0-preview.6" />
<PackageReference Include="WhateverDotNet.API.Abstractions" />
paket add WhateverDotNet.API.Abstractions --version 0.1.0-preview.6
#r "nuget: WhateverDotNet.API.Abstractions, 0.1.0-preview.6"
#:package WhateverDotNet.API.Abstractions@0.1.0-preview.6
#addin nuget:?package=WhateverDotNet.API.Abstractions&version=0.1.0-preview.6&prerelease
#tool nuget:?package=WhateverDotNet.API.Abstractions&version=0.1.0-preview.6&prerelease
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 responsesRequestSent/ResponseReceivedevents 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
RequestSentandResponseReceivedevents for custom logging hooks - Optional structured tracing via
ILogger<BaseJsonRestClient>
- Sends requests via an initialized
- Options:
BaseJsonRestClientOptions(BaseUrl,Timeout) - Events:
CustomApiCallLoggerEventArgs(caller method, HTTP method, endpoint path, serialized payload) - Logging:
ITestExecutionLogger(test output abstraction)NUnitTestExecutionLogger(writes toConsole)ILogMessageFormatter/ApiLogMessageFormatter(human-readable step messages)
- DI:
ServiceCollectionExtensionsAddApiLogMessageFormatter()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
BaseJsonRestClientexpects_httpClientto be initialized (for example viaCreateClient(...)). If it isn't, calls throwHttpClientNotInitializedException.- API-call logging is opt-in: subscribe to
RequestSent/ResponseReceivedand wire your ownITestExecutionLogger, 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:
BaseJsonRestClientno longer acceptsILogMessageFormatter/ITestExecutionLoggerin its constructor. Use theRequestSentandResponseReceivedevents instead. - Added
CustomApiCallLoggerEventArgsandRequestSent/ResponseReceivedevents for extensible API-call logging. - Added
TryPostAsJsonAsync<TResponse>overload without a request body. CreateClientnow throwsArgumentException(instead ofArgumentNullException) for blank tokens or missing base URLs.
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.8)
- Microsoft.Net.Http.Headers (>= 10.0.8)
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.