Repository navigation
Description
Problem
The Pathoschild.Http.FluentClient package depends on Microsoft.AspNet.WebApi.Client, which originates from the aspnet/AspNetWebStack repository. That is the legacy ASP.NET stack for MVC 5.x, Web API 2.x, and Web Pages 3.x.
This dependency is problematic for several reasons:
- End of support: ASP.NET Web API 2 reached end of support on July 1, 2019.
- No active development: No stable source release since October 2020 (5+ years).
System.Net.Http.Formattingand theMediaTypeFormatterabstraction were deliberately not brought forward to ASP.NET Core- Newtonsoft.Json: The package pulls in a transitive dependency on
Newtonsoft.Json. .NET moved toSystem.Text.Jsonas the platform default since .NET Core 3.0. System.Net.Http.Json(actively maintained in dotnet/runtime) is the official successor for HTTP content serialization.
Prior discussion
This has come up several times:
- Remove System.Net.Http.Formatting dependency #52 (2017) asked for removal, closed as wontfix
- Review supported frameworks #91 (2020) asked to modernize targets, declined
- Vulnerabilities Detected #120 (2022) related discussion
- System.Text.Json - json formatter #128 (2024) asked about System.Text.Json support
From #128: MediaTypeFormatter concept is a legacy part that the .NET team chose not to bring forward.
-
System.Net.Http.Jsondesign doc explains why they created a new assembly instead of extendingSystem.Net.Http.Formatting: "The existing assembly (which ships in Microsoft.AspNet.WebApi.Client package) provides the integration between HttpClient and JSON.NET. Mixing this with the new System.Text.Json would create a mess." -
.NET runtime code in
dotnet/runtime'sHttpMessageHandlerBuilder.csexplicitly avoids the old package: "This is similar to [System.Net.Http.Formatting/HttpClientFactory.cs] but we don't want to take that package as a dependency." -
David Fowler explained in dotnet/aspnetcore#3313 why the shared HTTP model that
MediaTypeFormatterdepended on was abandoned.
The modern approach is System.Net.Http.Json with simple extension methods (GetFromJsonAsync<T>(), etc.) no formatters, no content negotiation. A rewrite toward that model would be cleaner but would break the entire
public API surface (Formatters on IClient/IRequest/IResponse, IBodyBuilder.Model(), MediaTypeFormatterBase subclasses, etc.). That felt too disruptive for this change.
Proposed solution
Replace Microsoft.AspNet.WebApi.Client with lightweight, built-in abstractions:
- Define a new
IMediaTypeFormatterinterface (replacingSystem.Net.Http.Formatting.MediaTypeFormatter) - Provide
JsonMediaTypeFormatter(usingNewtonsoft.Json, preserving existing behavior) andXmlMediaTypeFormatter(usingDataContractSerializer) - Create a
MediaTypeFormatterCollection(same class name to minimize consumer breakage) - Update target frameworks to
netstandard2.0;net8.0
This removes the legacy dependency while keeping Newtonsoft.Json for backward compatibility (consumers can still configure JSON serialization the same way). A future version could add System.Text.Json support as an alternative formatter.
What could be added later (non-breaking):
- A
SystemTextJsonMediaTypeFormatterso consumers can choose between Newtonsoft.Json and System.Text.Json - Make System.Text.Json the default, with Newtonsoft.Json as opt-in
PR #134
Activity
Replace Microsoft.AspNet.WebApi.Client with built-in formatter abstra…
Replace Microsoft.AspNet.WebApi.Client with built-in formatter abstra…
Pathoschild commentedon Mar 4, 2026
(The prior discussions you mention seem mostly unrelated:
)
Pathoschild commentedon Mar 4, 2026
Hi! Microsoft's new philosophy seems to be that HttpClient just handles transport, and deserialization should be handled at a higher level.
I don't mind updating FluentHttpClient to match that philosophy, but it puts us in an awkward spot:
MediaTypeFormatter(like your PR does), all code which uses that feature will break since none of the implementations use our custom interface. So: major breaking change.HttpClientversions, we lose API parity between target frameworks. So: major breaking change.Since it's a big breaking change either way, maybe we should just plan for a FluentHttpClient 5.0.0 which revamps the API design across all target frameworks instead of trying to unify the legacy and modern approaches (which isn't possible).
That would mean:
Should we support content negotiation at all by default?
FluentHttpClient is meant to be a thin wrapper around
HttpClient, but content negotiation is in a gray area between wrapper features (like filters) and custom client logic. Reimplementing the fullMediaTypeFormatterecosystem isn't in scope for this library, and I think it's rarely needed (since we usually know which formats a given API uses).If we switch to extension-based deserialization methods, re-adding content negotiation as optional extensions using
Microsoft.AspNet.WebApi.Clientshould be pretty straightforward if we want to.Since we're already changing the API, we can also switch to System.Text.Json by default (while still allowing Json.NET or custom deserializers as an option).
This is a good opportunity to address API design issues like #129 (e.g. make it easier to properly dispose the response).
I'd be interested in @Jericho's thoughts on a 5.0.0 API redesign too.
Jericho commentedon Mar 4, 2026
I am 100% on board with major changes, even if it "costs" me time and effort when I eventually transition to FluentHttpClient 5.0. I think the up-side (dropping legacy and obsolete references, modernizing the list of targeted frameworks, etc.) makes this effort totally worth it.
And I agree with your statement:
In the ten years or so that I have been using FluentHtpClient I can't recall a single scenario where having multiple formatters was beneficial to me. Like you said, the format used by a given API is typically well documented and you only need to convert data to/from this known format. In fact, the standard config for FluentHtpClient in my projects is to remove all the built-in formatters and replace them with a single one (which I wrote) to serialize/deserialize json using System.Text.Json. It looks like this:
jmbryan4 commentedon Mar 4, 2026
I like the idea of major changes for a 5.0 release too.
@Pathoschild What are your thoughts on targeting netstandard2.0 and net8.0 like StrongGrid's 0.115.0 release
My vote is no for the core/base. Most APIs today are JSON only.
You could have a WebApiFormatters extension for legacy consumers that do not want to change.
I like the idea of moving Json.NET to an extension package outside of the core one. That seems to be a common pattern in related libraries (Refit, Restsharp, etc.)
I think we can close this in favor of a major 5.0 refactor. I opened this issue and PR as a goal to not have the Microsoft.AspNet.WebApi.Client dependency.
Full Native AOT compatibility could be a good goal for 5.0 release too
Jericho commentedon Mar 7, 2026
@Pathoschild The more I think about it more I realize that what I appreciate the most about FluentHttpClient is: nice fluent syntax, configurable automatic retries, configurable interceptors (they allow me to catch errors, log diagnostic information, add OAuth token to all requests, etc.). It's not "content negotiation", as evidenced by the fact that I have turned off the built-in serializing/deserializing and I wrote my own custom code to achieve this. I'll go even further and say that content negotiation could be completely removed from FluentHttpClient and I would still be happy with the client.
I guess this means that I am leaning towards your idea of making FluentHttpClient
a thin wrapper around HttpClient.Here's my suggestion:
public static IRequest WithJsonBody<T>(this IRequest request, T body)which would convert an object of typeTinto HttpContent using Newtonsoft's Json.NET. Also, this package would contain a few extension methods off ofIResponseto convert the response payload to a Json document, convert the payload into a given model class, etc.Developers would be able to choose which of the two Json parsers they whish to use and they could even decide to use neither and perform serialization/deserialization themselves.
This would achieve a clean separation between the main FluentHttpClient and the Json parsers.
jmbryan4 commentedon Jun 30, 2026
@Pathoschild any update on this?
Pathoschild commentedon Jul 1, 2026
@jmbryan4 With the recent rise of AI, I've been forced to overhaul a lot of the work I do in the Stardew Valley modding community to keep up. So I haven't had time recently to plan out what the new API would look like unfortunately.
It's definitely still something I want to do though. Proposals are welcome if anyone wants to plan out a possible API or implementation before I can get back to this.