Trellis.Http 3.0.0-alpha.382

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

Trellis.Http

NuGet Package

HttpClient extensions that bridge HttpResponseMessage into Result<T> / Result<Maybe<T>> pipelines.

Installation

dotnet add package Trellis.Http

What we provide (v3 surface)

A single static class Trellis.Http.HttpResponseExtensions with the canonical HTTP result methods:

  • ToResultAsync(statusMap?) — bridge Task<HttpResponseMessage> into Task<Result<HttpResponseMessage>>; without a map, non-2xx statuses become typed failures.
  • ToResultAsync(mapper, ct) — body-aware bridge invoked only for non-success status codes.
  • HandleNotFoundAsync / HandleConflictAsync / HandleUnauthorizedAsync — single-status convenience entry points on Task<HttpResponseMessage>.
  • ReadJsonAsync<T> / ReadJsonMaybeAsync<T> — deserialize the body of Task<Result<HttpResponseMessage>> into T or Maybe<T>.
  • ReadJsonOrNoneOn404Async<T> — terminal optional-resource read where 404 maps to Ok(Maybe.None).

Quick example

using System.Text.Json.Serialization;
using Trellis;
using Trellis.Http;

public sealed record ProfileDto(string DisplayName);

[JsonSerializable(typeof(ProfileDto))]
public partial class ProfileJsonContext : JsonSerializerContext { }

var userId = "current-user";
var result = await httpClient.GetAsync("/profile", cancellationToken)
    .HandleNotFoundAsync(new Error.NotFound(ResourceRef.For("Profile", userId)))
    .ReadJsonAsync(ProfileJsonContext.Default.ProfileDto, cancellationToken);

Disposal contract

The library owns HttpResponseMessage disposal on terminal/transformative paths: ToResultAsync and Handle*Async dispose on the Fail path; ReadJson* always dispose after reading. Pass-through paths leave disposal to the caller. Programmer-error null-argument paths (e.g. client.GetAsync(...).HandleNotFoundAsync(null!)) await first, then dispose before throwing ArgumentNullException.

Strict-default behavior

ToResultAsync() without a statusMap produces typed errors with HTTP-specific cases wrapped in Error.TransportFault(new HttpError.*(...)). The strict default preserves Allow on 405 and Content-Range on 416. 401 does not carry parsed WWW-Authenticate challenges, and 429 / 503 do not preserve Retry-After into the error payload. Missing or unusable header values for 405 and 416 fall through to Error.Unexpected rather than fabricating misleading wire headers. 3xx responses fall through; redirect-aware callers should pass a statusMap.

Exception propagation

HttpRequestException, OperationCanceledException / TaskCanceledException, and JsonException (from ReadJsonMaybeAsync<T> / ReadJsonOrNoneOn404Async<T> on a 2xx invalid body) propagate through the chain rather than being mapped to Result.Fail. ReadJsonAsync<T> catches JsonException and returns Fail<Error.Unexpected> with structured position diagnostics only (no response body, no JsonException.Path).

Breaking changes from v1

Trellis.Http has collapsed from 60+ overloads to a small canonical method set. Removed verbs: HandleForbidden*, HandleClientError*, HandleServerError*, EnsureSuccess/EnsureSuccessAsync, HandleFailureAsync<TContext>, and all sync / Result<HRM> / HttpResponseMessage-receiver overloads. Renamed verbs: ReadResultFromJsonAsyncReadJsonAsync, ReadResultMaybeFromJsonAsyncReadJsonMaybeAsync. See the package README on GitHub for the full migration table.

Part of Trellis

This package is part of the Trellis framework.

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
3.0.0-alpha.382 37 6/12/2026
3.0.0-alpha.372 47 6/10/2026
3.0.0-alpha.360 60 6/7/2026
3.0.0-alpha.342 48 6/5/2026
3.0.0-alpha.337 50 6/3/2026
3.0.0-alpha.336 47 6/3/2026
3.0.0-alpha.304 51 5/29/2026
3.0.0-alpha.158 66 4/5/2026
3.0.0-alpha.157 71 4/4/2026
3.0.0-alpha.140 69 3/30/2026
3.0.0-alpha.137 68 3/27/2026
3.0.0-alpha.135 57 3/26/2026
3.0.0-alpha.127 61 3/23/2026
3.0.0-alpha.123 63 3/19/2026
3.0.0-alpha.118 74 3/14/2026
3.0.0-alpha.111 71 3/12/2026
3.0.0-alpha.104 64 3/9/2026
3.0.0-alpha.100 55 3/4/2026
3.0.0-alpha.99 60 3/4/2026
3.0.0-alpha.98 64 3/3/2026
Loading failed