Flurl HTTP client library extensions for NETCore and NET 5.0.
Package | Latest Stable |
---|---|
Flurl.Serialization.TextJson |
Flurl have a default JsonSerialization implementation registered globally using NewtonsoftJsonSerializer, but you can change it for any other implementation.
Install using the Flurl.Serialization.TextJson NuGet package:
PM> Install-Package Flurl.Serialization.TextJson
As explained in the Flurl documentation there are different ways to setup the default JsonSerializer:
- Call once at application startup:
var jsonSettings = new JsonSerializerOptions
{
IgnoreNullValues = true
};
FlurlHttp.Configure(settings => settings.WithTextJsonSerializer(jsonSettings));
- Configure using directly the FlurlClient
public class AppyApiClient
{
readonly IFlurlClient _client;
public AppyApiClient(HttpClient httpClient)
{
var jsonSettings = new JsonSerializerOptions
{
IgnoreNullValues = true
};
_client = new FlurlClient(httpClient).Configure(settings => settings.WithTextJsonSerializer(jsonSettings));
}
public Task<GetCustomerByIdQueryResult> Execute(GetCustomerByIdQuery query, CancellationToken cancellationToken)
{
return _client
.Request("queries/getCustomerById")
.PostJsonAsync(query, cancellationToken)
.ReceiveJson<GetCustomerByIdQueryResult>();
}
}
It would be awesome if you would like to contribute code or help with bugs. Just follow the guidelines CONTRIBUTING