MintPlayer.Http
10.4.1
See the version list below for details.
dotnet add package MintPlayer.Http --version 10.4.1
NuGet\Install-Package MintPlayer.Http -Version 10.4.1
<PackageReference Include="MintPlayer.Http" Version="10.4.1" />
<PackageVersion Include="MintPlayer.Http" Version="10.4.1" />
<PackageReference Include="MintPlayer.Http" />
paket add MintPlayer.Http --version 10.4.1
#r "nuget: MintPlayer.Http, 10.4.1"
#:package MintPlayer.Http@10.4.1
#addin nuget:?package=MintPlayer.Http&version=10.4.1
#tool nuget:?package=MintPlayer.Http&version=10.4.1
MintPlayer.Http
Request-first HTTP ergonomics for .NET:
- Keep full control over your
HttpRequestMessage(headers, cookies, auth, content, etc.). - Still enjoy one-liners for JSON/XML (de)serialization.
- Get actionable errors (response body included when available).
- And when you need more than “just the DTO”, use the
…WithMetamethods to grab the payload + status code + headers in one go.
Motivation
The defaultSystem.Net.Http.Jsonhelpers are convenient but inflexible: you lose easy access to cookies/headers and fine-grained request control.MintPlayer.Httpflips that: you build the request you want, then use lightweight helpers for reading JSON/XML and surfacing rich error context.
Simple example
I created a simple example in this repository
Install
dotnet add package MintPlayer.Http
Or reference the project directly in your solution.
Quick start
Build the request fluently (no manual property mutation needed)
using System.Net.Http;
using MintPlayer.Http;
record CreateWidget(string Name, string Color);
record WidgetDto(string Id, string Name, string Color);
using var client = new HttpClient();
// Start with the request...
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.example.com/widgets")
.WithAuthorizationBearer("your_jwt_here") // ← auth
.WithHeader("X-TraceId", Guid.NewGuid().ToString()) // ← any header
.WithJsonContent(new CreateWidget("Minty", "green")); // ← body
// ...and then deserialize the response in one line:
WidgetDto created = await client.FromJsonAsync<WidgetDto>(req, null, ct);
Need status code and headers too? Use …WithMeta
using var client = new HttpClient();
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.example.com/widgets")
.WithAuthorizationBearer("your_jwt_here") // ← auth
.WithHeader("X-TraceId", Guid.NewGuid().ToString()) // ← any header
.WithJsonContent(new CreateWidget("Minty", "green")); // ← body
var result = await client.FromJsonWithMetaAsync<WidgetDto>(req, null, ct);
// You get both the value and the metadata:
WidgetDto dto = result.Value;
HttpStatusCode status = result.StatusCode;
HttpResponseHeaders headers = result.Headers; // response headers
Uri location = result.Location; // recirect url
There are also response-first variants (when you already have a
HttpResponseMessage), e.g.ReadJsonWithMetaAsync<T>(),ReadJsonAsync<T>(),ReadXmlAsync<T>().
Deconstruct the result
You can also easily deconstruct the result tuple-style:
using var client = new HttpClient();
var req = new HttpRequestMessage(HttpMethod.Post, "https://api.example.com/widgets")
.WithAuthorizationBearer("your_jwt_here") // ← auth
.WithHeader("X-TraceId", Guid.NewGuid().ToString()) // ← any header
.WithJsonContent(new CreateWidget("Minty", "green")); // ← body
var (dto, status, headers) = await client.FromJsonWithMetaAsync<WidgetDto>(req, null, ct);
Request helpers (examples)
These are extension methods on HttpRequestMessage so you don't have to mutate properties manually:
.WithHeader(name, value)/.WithHeaders(IDictionary<string,string>).WithAuthorizationBearer(token)/.WithAuthorizationBasic(username, password).WithCookie(uri, name, value)(when using a cookie container).WithJsonContent(value)(usesSystem.Text.Json).WithFormUrlEncodedContent(IEnumerable<KeyValuePair<string,string>> form).WithMultipartContent(c => { }).WithStringContent(str)(serialize to XML).WithXmlContent(value)(serialize to XML)
Exact names/overloads may differ slightly; check the source for the full list in
HttpRequestMessageExtensions.csandHttpResponseMessageExtensions.cs.
Response helpers
When you already have a HttpResponseMessage (e.g., because you needed ResponseHeadersRead, rate-limit headers, etc.):
using var res = await client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, ct);
// Throws with an error message that includes the response body when available.
await res.EnsureSuccessWithBodyAsync(ct);
// Just the DTO
var dto = await res.ReadJsonAsync<MyDto>(null, ct);
// DTO + metadata
var meta = await res.ReadJsonWithMetaAsync<MyDto>(ct);
// meta.Value, meta.StatusCode, meta.Headers
XML equivalents are available as well (ReadXmlAsync<T>, ReadXmlWithMetaAsync<T>).
End-to-end examples
A) GET with cookies + read JSON with metadata
var handler = new HttpClientHandler
{
UseCookies = true,
CookieContainer = new CookieContainer(),
};
using var client = new HttpClient(handler);
var req = new HttpRequestMessage(HttpMethod.Get, "https://api.example.com/me")
.WithCookie(new Uri("https://api.example.com"), "session", "abc123")
.AcceptJson();
var result = await client.FromJsonWithMetaAsync<UserDto>(req, null, ct);
Console.WriteLine($"Status: {(int)result.StatusCode}");
if (result.Headers.TryGetValues("x-ratelimit-remaining", out var values))
{
Console.WriteLine($"Rate remaining: {values.FirstOrDefault()}");
}
B) Response-first with streaming (large payloads)
var req = new HttpRequestMessage(HttpMethod.Get, "https://api.example.com/huge")
.Accept("application/octet-stream");
using var res = await client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, ct);
await res.EnsureSuccessWithBodyAsync(ct);
await using var stream = await res.Content.ReadAsStreamAsync(ct);
// process stream…
C) Get response stream directly
using var client = new HttpClient();
var httpStream = await client.FromStreamAsync(new HttpRequestMessage(HttpMethod.Get, download.resultDatasetDownloadUrl)
.WithHeader("Authorization", $"token {app.token}"));
using var archive = new ZipArchive(httpStream, ZipArchiveMode.Read, true);
var entry = archive.Entries.First();
Error handling
EnsureSuccessWithBodyAsync() is like EnsureSuccessStatusCode() but includes the response body in the exception message when possible—hugely helpful when APIs return details in JSON/text.
try
{
var dto = await client.FromJsonAsync<MyDto>(req, null, ct);
}
catch (HttpRequestException ex)
{
// ex.Message contains status + a snippet of the response body (when available)
_logger.LogError(ex, "Call failed");
}
Custom JSON options
Pass your own JsonSerializerOptions or source-gen context when reading:
var opts = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
};
var dto = await client.FromJsonAsync<MyDto>(req, opts, ct);
FAQ
How is this different from System.Net.Http.Json?
You don't give up request control. You assemble the exact HttpRequestMessage you want (headers, cookies, auth, body), then call FromJsonAsync/FromXmlAsync or the response-first Read…/…WithMeta helpers.
What do the …WithMeta methods return?
A lightweight result object that contains the deserialized value plus status code and headers (both response + content headers).
Does it work with Polly/handlers/logging?
Yes—everything sits on top of the standard HttpClient pipeline.
Cancellation tokens?
All async helpers accept a CancellationToken.
Requirements
- Recent .NET (as targeted by the project)
System.Text.Json(inbox on modern .NET)
Contributing
PRs welcome! Keep extensions small and composable, add tests, and document new helpers with a short example.
Source
- Request helpers:
HttpRequestMessageExtensions.cs - Response helpers:
HttpResponseMessageExtensions.cs
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- No dependencies.
-
net9.0
- No dependencies.
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 |
|---|---|---|
| 11.0.0 | 95 | 11/15/2026 |
| 11.0.0-rc.1 | 84 | 9/17/2026 |
| 10.4.1 | 147 | 8/27/2026 |
| 10.3.1 | 112 | 8/27/2026 |
| 10.3.0 | 357 | 11/11/2025 |
| 10.3.0-rc.1 | 268 | 11/10/2025 |
| 10.2.0 | 229 | 10/16/2025 |
| 10.1.0 | 231 | 9/21/2025 |
| 10.0.0 | 221 | 9/21/2025 |
| 10.0.0-rc.6 | 207 | 9/20/2025 |
| 10.0.0-rc.5 | 200 | 9/20/2025 |
| 10.0.0-rc.4 | 257 | 9/19/2025 |
| 10.0.0-rc.3 | 253 | 9/19/2025 |
| 10.0.0-rc.2 | 262 | 9/19/2025 |
| 10.0.0-rc.1 | 260 | 9/19/2025 |