CasCap.Common.Net
4.17.0
Prefix Reserved
dotnet add package CasCap.Common.Net --version 4.17.0
NuGet\Install-Package CasCap.Common.Net -Version 4.17.0
<PackageReference Include="CasCap.Common.Net" Version="4.17.0" />
<PackageVersion Include="CasCap.Common.Net" Version="4.17.0" />
<PackageReference Include="CasCap.Common.Net" />
paket add CasCap.Common.Net --version 4.17.0
#r "nuget: CasCap.Common.Net, 4.17.0"
#:package CasCap.Common.Net@4.17.0
#addin nuget:?package=CasCap.Common.Net&version=4.17.0
#tool nuget:?package=CasCap.Common.Net&version=4.17.0
CasCap.Common.Net
Abstract base class, extensions, and authentication handlers for building typed HttpClient wrappers and securing ASP.NET Core APIs.
Installation
dotnet add package CasCap.Common.Net
Target frameworks: netstandard2.0, net8.0, net9.0, net10.0
The HTTP client base, authentication handler, resilience and auditing APIs require .NET 8+. The .NET Standard target exposes the applicable network extensions.
Usage
Derive a typed client from HttpClientBase, pass its logger and HttpClient to the base constructor,
and register it with IHttpClientFactory:
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using CasCap.Common.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHttpClient<ExampleClient>(client =>
client.BaseAddress = new Uri("https://example.com/api/"));
public sealed class ExampleClient(ILogger<ExampleClient> logger, HttpClient client)
: HttpClientBase(logger, client)
{
public Task<(string? result, string? error)> GetStatusAsync(CancellationToken cancellationToken)
=> GetAsync<string, string>("status", cancellationToken: cancellationToken);
}
The GET and POST helpers take TResult and TError types. string returns the raw body and byte[] returns
the raw bytes, so an endpoint answering with audio or any other binary payload needs no separate
plumbing; other result types are deserialized as JSON. The Async-suffixed helpers return
(result, error); their counterparts also return the status code and response headers. Both forms
are asynchronous. Handle the error result as well as the successful result.
| Request | Helpers |
|---|---|
| GET | GetAsync, Get |
| JSON POST | PostJsonAsync, PostJson |
| Binary POST | PostBytesAsync, PostBytes |
| Multipart POST | PostMultipartAsync, PostMultipart |
Calls support cancellation, timeouts and additional headers. The caller owns and disposes
MultipartFormDataContent, including its parts.
Retry Safety
AddStandardResilience adds retry, circuit breaker and timeout handling. Its default
HttpRetrySafety.SafeMethodsOnly permits replay for idempotent methods. POST and PATCH retry only
for failures indicating the request never reached the server, not for timeouts or server errors.
Use AllMethods only when the endpoint's contract makes replay safe; use Never to disable retries.
using CasCap.Common.Extensions;
using CasCap.Common.Models;
builder.Services.AddHttpClient<ExampleClient>()
.AddStandardResilience(nameof(ExampleClient), HttpRetrySafety.SafeMethodsOnly);
Apply the extension to the same registration that configures the client's base address.
Authentication
BasicAuthenticationHandler validates HTTP Basic credentials against ApiAuthConfig. Bind and
register those options through the application's authentication setup. Supply credentials through
a secret provider and use TLS. AnonymousPathPrefixes defaults to ["/healthz"]; review bypasses
before exposing endpoints.
For outgoing requests, NetExtensions supplies GetBasicAuthHeaderValue and SetBasicAuth.
Do not log the resulting header.
Configuration Examples
The client and resilience helpers use registration arguments, not a fixed JSON section. The
authentication handler consumes CasCap:ApiAuthConfig through options supplied by the application.
Provide its required username and password through a secret provider.
Default Anonymous Probe Path
{
"CasCap": {
"ApiAuthConfig": {
"AnonymousPathPrefixes": ["/healthz"]
}
}
}
Require Authentication on Every Path
{
"CasCap": {
"ApiAuthConfig": {
"AnonymousPathPrefixes": []
}
}
}
These fragments configure only path bypasses; neither is sufficient without the secret-backed credentials and the application's authentication scheme registration.
HTTP Auditing
AddHttpAuditing(sourceName) adds a handler that captures the request path/query, method, status,
elapsed time and request/response bodies. By default it registers NullHttpAuditStore and persists
nothing. Supply an
IHttpAuditStore
implementation to retain records.
Captured bodies are JSON representations: absent, empty or whitespace-only content becomes
null; valid JSON objects, arrays and scalars retain their original text; plain text, HTML and
malformed JSON become JSON strings preserving the original content. Normalization changes only
the audit record, never the HTTP request or response. Stores can therefore accept ordinary empty
and non-JSON responses without attempting to parse them as raw JSON.
FileHttpAuditStore writes JSON under daily folders, defaulting to http-audit relative to the
working directory. It has no automatic retention policy. Capture is not redaction: paths, query
parameters and bodies may contain credentials or personal data. Assess the data and configure
appropriate access, retention and consent before enabling persistence. Body capture also buffers
content; do not assume it is suitable for large or streaming payloads.
Network Extensions
NetExtensions supplies query-string construction, header replacement and response-header lookup.
These helpers do not register clients or send requests by themselves.
Class Hierarchy
The typed client owns its API-specific methods; the base class handles common HTTP operations.
classDiagram
direction TB
HttpClientBase <|-- ExampleClient
class HttpClientBase {
<<abstract>>
+HttpClient Client
#ILogger _logger
#PostJsonAsync~TResult,TError~(uri, body) Task
#PostBytesAsync~TResult,TError~(uri, bytes) Task
#PostMultipartAsync~TResult,TError~(uri, content) Task
#GetAsync~TResult,TError~(uri) Task
}
class ExampleClient {
+GetStatusAsync(cancellationToken) Task
}
HttpClientBase ..> ILogger : uses
HttpClientBase ..> HttpClient : uses
For the authentication and audit contracts, see CasCap.Common.Abstractions.
| 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 is compatible. 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 is compatible. 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 was computed. |
| .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
- CasCap.Common.Abstractions (>= 4.17.0)
- CasCap.Common.Logging (>= 4.17.0)
- CasCap.Common.Serialization.Json (>= 4.17.0)
-
net10.0
- CasCap.Common.Abstractions (>= 4.17.0)
- CasCap.Common.Logging (>= 4.17.0)
- CasCap.Common.Serialization.Json (>= 4.17.0)
- Microsoft.Extensions.Http.Resilience (>= 10.11.0)
-
net8.0
- CasCap.Common.Abstractions (>= 4.17.0)
- CasCap.Common.Logging (>= 4.17.0)
- CasCap.Common.Serialization.Json (>= 4.17.0)
- Microsoft.Extensions.Http.Resilience (>= 10.11.0)
-
net9.0
- CasCap.Common.Abstractions (>= 4.17.0)
- CasCap.Common.Logging (>= 4.17.0)
- CasCap.Common.Serialization.Json (>= 4.17.0)
- Microsoft.Extensions.Http.Resilience (>= 10.11.0)
NuGet packages (11)
Showing the top 5 NuGet packages that depend on CasCap.Common.Net:
| Package | Downloads |
|---|---|
|
CasCap.Apis.GooglePhotos
Fully featured .NET library/wrapper for the Google Photos REST API. This *unofficial* library enables programmatic access to the media items and albums of a Google Photos account. The library leverages the authentication in the official Google.Apis.Auth library and builds on that by encapsulating all REST API calls in an efficient wrapper returning strongly-typed objects. For more details about the underlying API see the official site, https://developers.google.com/photos For usage examples see the docs on github, https://github.com/f2calv/CasCap.Apis.GooglePhotos |
|
|
CasCap.Api.GooglePhotos
.NET client library for the Google Photos Library and Picker APIs. This unofficial library manages application-created media and albums through the Library API and accesses user-selected existing media through the Picker API. The library leverages the authentication in the official Google.Apis.Auth library and builds on that by encapsulating all REST API calls in an efficient wrapper returning strongly-typed objects. For more details about the underlying API see the official site, https://developers.google.com/photos For usage examples see the docs on github, https://github.com/f2calv/CasCap.Api.GooglePhotos |
|
|
CasCap.Apis.AzureDevOps
Azure DevOps helper/utility library. |
|
|
CasCap.Api.AzureDevOps
Azure DevOps helper/utility library. |
|
|
CasCap.Api.SignalCli
Typed .NET client for the signal-cli REST API with REST polling and JSON-RPC WebSocket transports, webhook endpoints, health checks, and INotifier integration. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.17.0 | 72 | 10/24/2026 |
| 4.16.0 | 242 | 10/21/2026 |
| 4.15.0 | 192 | 10/6/2026 |
| 4.14.4 | 357 | 10/4/2026 |
| 4.14.3 | 164 | 9/28/2026 |
| 4.14.2 | 328 | 9/25/2026 |
| 4.14.1 | 415 | 9/23/2026 |
| 4.14.0 | 611 | 9/19/2026 |
| 4.13.0 | 140 | 9/15/2026 |
| 4.12.8 | 358 | 9/10/2026 |
| 4.12.7 | 451 | 9/4/2026 |
| 4.12.6 | 162 | 9/1/2026 |
| 4.12.5 | 188 | 8/20/2026 |
| 4.12.4 | 354 | 8/18/2026 |
| 4.12.3 | 305 | 7/15/2026 |
| 4.12.2 | 303 | 6/26/2026 |
| 4.12.1 | 296 | 6/14/2026 |
| 4.12.0 | 278 | 6/12/2026 |
| 4.11.9 | 289 | 6/10/2026 |
| 4.11.8 | 251 | 5/27/2026 |