Soenneker.Extensions.HttpResponseMessage
4.0.2459
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Extensions.HttpResponseMessage --version 4.0.2459
NuGet\Install-Package Soenneker.Extensions.HttpResponseMessage -Version 4.0.2459
<PackageReference Include="Soenneker.Extensions.HttpResponseMessage" Version="4.0.2459" />
<PackageVersion Include="Soenneker.Extensions.HttpResponseMessage" Version="4.0.2459" />
<PackageReference Include="Soenneker.Extensions.HttpResponseMessage" />
paket add Soenneker.Extensions.HttpResponseMessage --version 4.0.2459
#r "nuget: Soenneker.Extensions.HttpResponseMessage, 4.0.2459"
#:package Soenneker.Extensions.HttpResponseMessage@4.0.2459
#addin nuget:?package=Soenneker.Extensions.HttpResponseMessage&version=4.0.2459
#tool nuget:?package=Soenneker.Extensions.HttpResponseMessage&version=4.0.2459
Soenneker.Extensions.HttpResponseMessage
Response-body conversion, status-aware results, media-type inspection, and bounded diagnostic logging for HttpResponseMessage.
Installation
dotnet add package Soenneker.Extensions.HttpResponseMessage
Require a successful JSON response
using Soenneker.Extensions.HttpResponseMessage;
using HttpResponseMessage response = await httpClient.GetAsync(uri, cancellationToken);
await response.EnsureSuccess(logger, cancellationToken);
OrderDto order = await response.ToStrict<OrderDto>(logger, cancellationToken);
EnsureSuccess() returns immediately for a successful status. For a failure it can log a non-binary, small body at Information, then throws through EnsureSuccessStatusCode(). ToStrict<T>() requires a nonempty JSON body and throws when reading or deserialization fails; it does not check the HTTP status itself.
Both methods consume the response body. Keep the response alive until conversion finishes and dispose it afterward.
Convert without throwing on malformed content
CustomerDto? customer = await response.To<CustomerDto>(logger, cancellationToken);
To<T>() returns default for no content, unreadable content, non-JSON content, and deserialization failures. It does not treat a non-success status as a conversion failure: if that response contains compatible JSON, it can still return T. Read and conversion failures can be logged; cancellation requested through the supplied token still propagates.
Use ToWithString<T>() when the raw response text is needed alongside the attempted conversion:
(CustomerDto? customer, string? raw) =
await response.ToWithString<CustomerDto>(logger, cancellationToken);
The tuple contains the raw body even when JSON conversion fails. A read failure produces (default, null), while a known no-content response produces (default, "").
For XML, ToFromXml<T>() follows the forgiving pattern and returns default on read or deserialization failure.
Produce an operation result
OperationResult<CustomerDto> result =
await response.ToResult<CustomerDto>(logger, cancellationToken);
ToResult<T>() is status-aware:
- A successful response with valid JSON becomes a successful result containing
T. - A non-success response containing
ProblemDetailsDtobecomes a failed result with those details. - Missing, malformed, or unexpected content becomes a failed result with the package's generic error message.
- Status
204, status205, or a declared zero-length body becomes an empty result carrying the HTTP status.
Overloads accepting JsonTypeInfo<T> are available for source-generated JSON metadata on To<T>(), ToStrict<T>(), and ToResult<T>().
Read or log response text
string? body = await response.ToStringSafe(logger, cancellationToken);
string bodyOrThrow = await response.ToStringStrict(cancellationToken);
await response.LogResponse(logger, cancellationToken);
ToStringSafe() returns null on read failure and an empty string for recognized binary media types. ToStringStrict() delegates to ReadAsStringAsync() and lets failures propagate. LogResponse() writes a debug preview only when debug logging is enabled, the media type is not recognized as binary, and the declared body size is small enough to buffer.
Conversion warnings and errors can include a preview of response content. Do not enable these logs for secrets, credentials, or personal data unless the destination and retention policy are appropriate.
Inspect response metadata
IsNoContent()recognizes status204, status205, and a declaredContent-Lengthof zero.IsJson()recognizesapplication/jsonand media types ending in+json.IsProblemJson()recognizesapplication/problem+json.IsXml()recognizesapplication/xml,text/xml, and media types ending in+xml.LooksBinary()recognizes image, audio, video, andapplication/octet-streammedia types.
These checks use response metadata; they do not inspect or validate the complete body.
| 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
- Soenneker.Constants.UserMessages (>= 4.0.22)
- Soenneker.Extensions.Dtos.ProblemDetails (>= 4.0.61)
- Soenneker.Extensions.HttpContent (>= 4.0.950)
- Soenneker.Streams.Prefixed (>= 4.0.30)
- Soenneker.Utils.Json (>= 4.0.2660)
- Soenneker.Utils.Xml (>= 4.0.1123)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Soenneker.Extensions.HttpResponseMessage:
| Package | Downloads |
|---|---|
|
Soenneker.Extensions.HttpClient
A collection of helpful HttpClient extension methods, like retry and auto (de)serialization |
|
|
Soenneker.Blazor.Consumers.Base
A wrapper around Soenneker.Blazor.ApiClient supporting auto (de)serialization for requests/responses/ProblemDetails. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.2460 | 0 | 8/31/2026 |
| 4.0.2459 | 0 | 8/31/2026 |
| 4.0.2458 | 0 | 8/31/2026 |
| 4.0.2456 | 0 | 8/30/2026 |
| 4.0.2453 | 44 | 8/30/2026 |
| 4.0.2451 | 55 | 8/30/2026 |
| 4.0.2450 | 29 | 8/30/2026 |
| 4.0.2449 | 158 | 8/30/2026 |
| 4.0.2447 | 36 | 8/30/2026 |
| 4.0.2445 | 38 | 8/30/2026 |
| 4.0.2444 | 74 | 8/30/2026 |
| 4.0.2442 | 61 | 8/30/2026 |
| 4.0.2441 | 377 | 8/30/2026 |
| 4.0.2438 | 228 | 8/29/2026 |
| 4.0.2437 | 40 | 8/29/2026 |
| 4.0.2436 | 36 | 8/29/2026 |
| 4.0.2435 | 42 | 8/29/2026 |
| 4.0.2434 | 747 | 8/26/2026 |
| 4.0.2433 | 225 | 8/26/2026 |
| 4.0.2432 | 285 | 8/26/2026 |
Update dependency Soenneker.Streams.Prefixed to 4.0.30 (#3007)