MonadicSharp.Http 1.0.0

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

MonadicSharp.Http

Result-aware HTTP client for .NET 8 — HTTP errors, timeouts, and deserialization failures are typed Result<T> values, never unhandled exceptions.

NuGet .NET


Overview

MonadicSharp.Http replaces the fragile try/catch pattern around HttpClient with Railway-Oriented error handling:

  • IHttpResultClient — typed interface for GET, POST, PUT, PATCH, DELETE
  • HttpResultClient — default implementation backed by HttpClient
  • RetryPolicy — typed retry with exponential backoff, composable with CircuitBreaker
  • HttpResultResponse<T> — wraps result + status code + response headers
  • HttpError — typed error factory for every HTTP failure scenario

Installation

dotnet add package MonadicSharp.Http

Basic Usage

// GET
Result<WeatherForecast> forecast =
    await httpClient.GetAsync<WeatherForecast>("/api/weather");

// POST
Result<OrderResponse> order =
    await httpClient.PostAsync<OrderRequest, OrderResponse>("/api/orders", orderRequest);

// Railway chain
var result = await httpClient
    .GetAsync<UserProfile>($"/api/users/{userId}")
    .BindAsync(profile => enrichmentAgent.ExecuteAsync(profile, context));

HttpResultResponse — Access Status & Headers

HttpResultResponse<Page> response =
    await httpClient.SendAsync<Page>(new HttpRequestMessage(HttpMethod.Get, "/api/page"));

Console.WriteLine(response.StatusCode);  // HttpStatusCode.OK
Console.WriteLine(response.Result.IsSuccess);
if (response.Headers.TryGetValue("X-Rate-Limit-Remaining", out var remaining))
    Console.WriteLine(remaining);

RetryPolicy

var retry = new RetryPolicy(
    maxAttempts: 3,
    initialDelay: TimeSpan.FromMilliseconds(200),
    backoffMultiplier: 2.0,
    retryOn: error => error.Code is "HTTP_429" or "HTTP_503");

var result = await retry.ExecuteAsync(
    ct => httpClient.GetAsync<Data>("/api/data", ct));

// On exhaustion: HttpError.RetryExhausted (contains lastError + attempt count)

Integration with CircuitBreaker

var breaker = new CircuitBreaker("ExternalApi", failureThreshold: 5);

var result = await retry.ExecuteAsync(
    ct => breaker.ExecuteAsync(
        innerCt => httpClient.GetAsync<Data>("/api/data", innerCt), ct));

Error Codes

Code HTTP Trigger
HTTP_NETWORK_FAILURE Network unreachable / DNS failure
HTTP_TIMEOUT HttpClient.Timeout exceeded
HTTP_CANCELLED CancellationToken triggered
HTTP_BAD_REQUEST 400
HTTP_UNAUTHORIZED 401
HTTP_FORBIDDEN 403
HTTP_NOT_FOUND 404
HTTP_CONFLICT 409
HTTP_UNPROCESSABLE_ENTITY 422
HTTP_RATE_LIMITED 429
HTTP_SERVER_ERROR 5xx
HTTP_DESERIALIZATION_FAILED JSON parse error on success response
HTTP_RETRY_EXHAUSTED All retry attempts consumed

DI Registration

// Registers IHttpResultClient + named HttpClient
services.AddMonadicSharpHttp("MyClient", client =>
{
    client.BaseAddress = new Uri("https://api.example.com");
    client.Timeout = TimeSpan.FromSeconds(30);
});

License

MIT — part of MonadicSharp.Framework.

Product 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 was computed.  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 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on MonadicSharp.Http:

Package Downloads
MonadicSharp.Framework

Meta-package for the MonadicSharp Framework — install this single package to get Agents, Caching, Http, Persistence, Security, and Telemetry in one shot. For à-la-carte usage, reference individual MonadicSharp.* packages instead.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 45 3/3/2026