Genocs.Http
9.0.0
Requires NuGet 5.0.0 or higher.
dotnet add package Genocs.Http --version 9.0.0
NuGet\Install-Package Genocs.Http -Version 9.0.0
<PackageReference Include="Genocs.Http" Version="9.0.0" />
<PackageVersion Include="Genocs.Http" Version="9.0.0" />
<PackageReference Include="Genocs.Http" />
paket add Genocs.Http --version 9.0.0
#r "nuget: Genocs.Http, 9.0.0"
#:package Genocs.Http@9.0.0
#addin nuget:?package=Genocs.Http&version=9.0.0
#tool nuget:?package=Genocs.Http&version=9.0.0
Genocs.Http

Http client abstractions and helpers for Genocs applications. Supports net10.0, net9.0, and net8.0.
Installation
dotnet add package Genocs.Http
Getting Started
Use this package to provide the base Http abstraction layer for outbound service calls and client configuration in Genocs services. Registration flows through Genocs.Core (IGenocsBuilder.AddHttpClient(...)).
Main Entry Points
AddHttpClient— registers a typedIHttpClient(GenocsHttpClient),HttpClientOptions, and the defaultSystemTextJsonHttpClientSerializer. Use the optionalhttpClientBuilderargument to callConfigureHttpClient(for example to setHttpClient.BaseAddressfor relative URI strings).
Configuration contract (httpClient)
AddHttpClient(...) binds HttpClientOptions from the httpClient section.
{
"httpClient": {
"enabled": true,
"type": "consul",
"retries": 3,
"retryUnsafeHttpMethods": false,
"services": {
"orders": "http://orders-service"
},
"removeCharsetFromContentType": true,
"correlationContextHeader": "x-correlation-context",
"correlationIdHeader": "x-correlation-id",
"requestMasking": {
"enabled": true,
"urlParts": ["token", "password"],
"maskTemplate": "*****"
}
}
}
Fields actively used by this package runtime:
retriesretryUnsafeHttpMethodsremoveCharsetFromContentTypecorrelationContextHeadercorrelationIdHeaderrequestMasking.enabledrequestMasking.urlPartsrequestMasking.maskTemplate
Fields currently present in the options contract but not implemented by this package runtime:
enabledtypeservices
Treat those fields as shared configuration shape unless a companion package documents concrete runtime behavior.
Response handling
- String URI, exception-oriented helpers —
GetAsync,PostAsync,GetAsync<T>,PostAsync<T>, and similar either returnHttpResponseMessageafter a successful status or throw when the status is not successful (typed methods deserialize only after success). - String URI, result-oriented helpers — Methods named
*ResultAsync<T>(string, ...)(for exampleGetResultAsync<T>,PostResultAsync<T>) returnHttpResult<T>for both success and failure status codes. InspectHttpResult<T>.Responsefor status and content; they do not throw solely because the HTTP status indicates an error. For non-success responses,Resultis typically the default value forT; useHasResultonly as a hint about a non-null deserialized payload. HttpRequestMessageoverloads —SendResultAsync<T>(HttpRequestMessage, ...)preserves non-success responses inHttpResult<T>.SendAsync<T>(HttpRequestMessage, ...)throws when the status is not successful (exception-oriented deserialization path). Request-message overloads send the providedHttpRequestMessageonce per call and do not internally retry by replaying that instance.- Response ownership — Typed methods that return
T?consume and dispose transientHttpResponseMessageinstances internally. Methods that returnHttpResponseMessageorHttpResult<T>transfer response ownership to the caller.
Retries
- Retries apply only to transport-level transient failures during send (for example
HttpRequestExceptionwithout a response status, retryableHttpRequestExceptionstatus codes, andIOException). - Retries apply to string-URI helper methods.
HttpRequestMessageoverloads intentionally do not replay the same message instance. - Cancellation-driven failures are not retried. User-triggered cancellation is surfaced immediately as
OperationCanceledException/TaskCanceledException. - HTTP error status codes are not retried by default. Exception-oriented methods still throw on non-success responses, but that happens after the retry boundary.
- Deserialization failures are not retried.
- By default, retries are limited to idempotent methods.
POST,PUT, andPATCHare excluded unless explicitly enabled. - Configure retry count via
httpClient.retriesand opt-in write-method retries viahttpClient.retryUnsafeHttpMethodsinHttpClientOptions. - Cancellation tokens are propagated through send, response-stream access, and payload deserialization paths.
Correlation headers
- Correlation headers are injected in a per-request handler, not in
HttpClient.DefaultRequestHeaders. - Header values are evaluated for each outbound request through
ICorrelationContextFactoryandICorrelationIdFactory. - If a caller already sets the configured correlation headers on
HttpRequestMessage, Genocs.Http preserves those values and does not overwrite them. - If header names are blank, or factory outputs are null/whitespace, no correlation headers are added.
- This request-scoped model avoids stale correlation values when typed clients are long-lived while still supporting singleton and scoped consumers.
Request masking
- Request masking applies to log URI rendering only. It does not modify the outbound request URI, request body, or headers.
- Masking uses exact-token replacement (
StringComparison.Ordinal) over the URI text rendered for logging (HttpRequestMessage.RequestUri.OriginalString). - All occurrences of each configured token are replaced, including path, query, and fragment segments.
- Masking is deterministic and safe for diagnostics rendering: replacement output is treated as plain log text and is not reparsed as a
Uri. - Empty or whitespace tokens are ignored.
Request URIs and BaseAddress
Request URI strings are parsed with
System.Uri(UriKind.RelativeOrAbsolute) after trimming. Null, whitespace-only, or unparseable values throwArgumentExceptionwith parameter nameuri.Pass absolute URIs (for example
https://api.contoso.com/v1/items) when you want a fully qualified destination; they are sent unchanged (no scheme or host rewriting).Pass relative paths (for example
items/5or/items/5) when the namedHttpClienthas aBaseAddressset, for example:AddHttpClient(..., httpClientBuilder: b => b.ConfigureHttpClient(c => c.BaseAddress = new Uri("https://api.contoso.com/v1/")))Resolution follows normal
HttpClient/Uricombination rules. Prefer aBaseAddressthat ends with/when you want relative segments to append as subpaths predictably.The client does not prepend
http://or guess a scheme for host-like strings. Upgrade note: older versions prependedhttp://when the string did not start withhttp; that behavior was removed. Use an absolute URI, or setBaseAddressand pass relative paths.If you use a relative URI without
BaseAddress,HttpClientfails when sending (for exampleInvalidOperationException); configure the base address explicitly rather than relying on implicit rewriting.
Additional examples
Configure BaseAddress for relative request paths
using Genocs.Core.Builders;
using Genocs.Http;
IGenocsBuilder genocs = builder.AddGenocs()
.AddHttpClient(httpClientBuilder: b =>
b.ConfigureHttpClient(c => c.BaseAddress = new Uri("https://catalog.internal/api/v1/")));
Override the default serializer
using System.Text.Json;
using Genocs.Http;
builder.Services.AddSingleton<IHttpClientSerializer>(
new SystemTextJsonHttpClientSerializer(
new JsonSerializerOptions(JsonSerializerDefaults.Web)
{
PropertyNameCaseInsensitive = true
}));
Add correlation factories and URL masking
using Genocs.Core.Builders;
using Genocs.Http;
builder.Services.AddSingleton<ICorrelationIdFactory, MyCorrelationIdFactory>();
builder.Services.AddSingleton<ICorrelationContextFactory, MyCorrelationContextFactory>();
IGenocsBuilder genocs = builder.AddGenocs()
.AddHttpClient(maskedRequestUrlParts: ["token", "password"]);
Masking applies only to HTTP-client URL log rendering, not to payloads or arbitrary log properties.
Resilience ownership guidance
- Genocs.Http already applies internal retry behavior for string-URI helper methods.
- If you also add
IHttpClientBuilderresilience handlers (for example retry/timeout/circuit-breaker), evaluate the combined strategy to avoid duplicate retry amplification. - Keep retry ownership explicit per outbound call path: either rely on Genocs.Http defaults, or move strategy ownership to pipeline handlers and tune Genocs retries conservatively.
HttpRequestMessageoverloads are single-send by design; if replay behavior is required, implement replay-safe resilience at the handler/pipeline layer.
Migration notes (April 2026)
When upgrading from older Genocs.Http behavior, review these consumer-visible changes:
- String
*ResultAsync<T>(...)methods preserve non-success responses inHttpResult<T>instead of throwing solely for status. - URI inputs follow standard
System.Urirules only; there is no implicithttp://prefixing. - Retries are transport-focused; non-success HTTP statuses and deserialization failures are not retried by default.
- Retries for
POST/PUT/PATCHrequire explicit opt-in viahttpClient.retryUnsafeHttpMethods=true. HttpRequestMessageoverloads are single-send and do not replay the same request instance.- Correlation headers are injected per request and do not overwrite caller-supplied request headers.
- URL masking applies only to logged URI text and does not redact bodies/headers.
For a source-blind upgrade checklist and decision guidance, see Genocs.Http-Agent-Documentation.md.
Validation
dotnet build src/Genocs.Http/Genocs.Http.csproj -c Debug --nologo
dotnet test src/tests/Genocs.Http.UnitTests/Genocs.Http.UnitTests.csproj -c Debug --nologo
Maintainer quality gates
Genocs.Http applies package-level quality gates in Genocs.Http.csproj to reduce contract regressions:
- nullable warnings are treated as errors (
WarningsAsErrorsincludesnullable) - .NET analyzer warnings are treated as errors for this package (
CodeAnalysisTreatWarningsAsErrors=true)
This gate is intentionally package-scoped (not repository-wide) so maintainers can harden outbound HTTP public-surface behavior without forcing unrelated projects to adopt the same baseline immediately.
Further documentation
- Agent-oriented reference (semantics, recipes, troubleshooting): Genocs.Http-Agent-Documentation.md
- Implementation backlog and roadmap: Genocs.Http-Implementation-Backlog.md
Support
- Documentation Portal: https://learn.fiscanner.net/
- Documentation: https://github.com/Genocs/genocs-library/tree/main/docs
- Repository: https://github.com/Genocs/genocs-library
Release Notes
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- Genocs.Core (>= 9.0.0)
- Microsoft.Extensions.Http (>= 10.0.7)
- Polly (>= 8.6.6)
-
net8.0
- Genocs.Core (>= 9.0.0)
- Microsoft.Extensions.Http (>= 10.0.7)
- Polly (>= 8.6.6)
-
net9.0
- Genocs.Core (>= 9.0.0)
- Microsoft.Extensions.Http (>= 10.0.7)
- Polly (>= 8.6.6)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Genocs.Http:
| Package | Downloads |
|---|---|
|
Genocs.Discovery.Consul
Consul-based service discovery integration for Genocs applications. |
|
|
Genocs.ServiceDiscovery.Consul
Consul-based service discovery integration for Genocs applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 9.0.0 | 161 | 5/21/2026 |
| 9.0.0-beta009 | 175 | 5/11/2026 |
| 9.0.0-beta008 | 205 | 5/2/2026 |
| 9.0.0-beta007 | 167 | 4/29/2026 |
| 9.0.0-beta006 | 153 | 4/27/2026 |
| 9.0.0-beta005 | 164 | 4/26/2026 |
| 9.0.0-beta004 | 156 | 4/18/2026 |
| 9.0.0-beta003 | 182 | 4/5/2026 |
| 9.0.0-beta002 | 207 | 3/17/2026 |
| 9.0.0-beta001 | 184 | 2/28/2026 |
| 8.1.0 | 228 | 2/8/2026 |
| 8.0.0 | 2,687 | 11/23/2025 |
| 7.5.1 | 2,717 | 10/19/2025 |
| 7.5.0 | 5,408 | 10/12/2025 |
| 7.4.1 | 2,105 | 9/19/2025 |
| 7.4.0 | 371 | 9/19/2025 |
| 7.3.0 | 8,457 | 8/14/2025 |
| 7.2.5 | 13,781 | 5/1/2025 |
| 7.2.4 | 2,284 | 4/18/2025 |
| 7.2.3 | 17,337 | 1/20/2025 |
The change log and breaking changes are listed here.
https://github.com/Genocs/genocs-library/releases