Enable Newtonsoft serialization globally for clientless pattern
devFlurlHttp.Clients.UseNewtonsoft().repository·dev·Indexed 26 days ago
https://github.com/tmenier/flurlA modern, fluent, and asynchronous URL builder and HTTP client library for .NET. Flurl provides a streamlined API for constructing complex URLs and executing HTTP requests, including a built-in HttpTest utility for faking and recording calls during unit tests. Available as a standalone URL builder (Flurl) or a full HTTP client (Flurl.Http), with optional Newtonsoft.Json support via Flurl.Http.Newtonsoft for compatibility and dynamic-returning extension methods.
FlurlHttp.Clients.UseNewtonsoft().Newtonsoft.Json to System.Text.Json. To continue using Newtonsoft-based serialization and maintain compatibility with Newtonsoft attributes and settings, install the Flurl.Http.Newtonsoft NuGet package.You can install Flurl using the NuGet Package Manager.
To install the full HTTP client library (includes URL building and HTTP features), use:
Install-Package Flurl.Http
To install only the standalone URL builder without HTTP features, use:
Install-Package Flurl
PM> Install-Package Flurl.Http.UseNewtonsoft() on a FlurlClientCache instance.Flurl includes HttpTest to allow you to fake and record all HTTP calls made by your code during unit tests. You can use it to arrange responses and assert that specific calls were made with the expected verb and content type.
[Test]
public void Can_Create_Person() {
// fake & record all http calls in the test subject
using var httpTest = new HttpTest();
// arrange
httpTest.RespondWith("OK", 200);
// act
await sut.CreatePersonAsync("Frank", "Reynolds");
// assert
httpTest.ShouldHaveCalled("http://api.mysite.com/*")
.WithVerb(HttpMethod.Post)
.WithContentType("application/json");
}Flurl provides a fluent API for building URLs and making asynchronous HTTP requests. You can chain methods to append path segments, set query parameters, add authentication headers, and send JSON payloads.
var result = await "https://api.mysite.com"
.AppendPathSegment("person")
.SetQueryParams(new { api_key = "xyz" })
.WithOAuthBearerToken("my_oauth_token")
.PostJsonAsync(new { first_name = firstName, last_name = lastName })
.ReceiveJson<T>();NewtonsoftJsonSerializer instance to a specific Flurl client or request via the Settings.JsonSerializer property. Both the serializer and the UseNewtonsoft shortcuts accept an optional JsonSerializerSettings parameter.Because System.Text.Json lacks support for dynamic, Flurl 4.0 removed dynamic support. This package provides non-generic dynamic-returning extension methods to restore this functionality:
GetJsonGetJsonListReceiveJsonReceiveJsonList