Skip to content

Flurl http and serialization extensions

License

Notifications You must be signed in to change notification settings

YellowLineParking/Appy.Flurl

Repository files navigation

App.Flurl

AppyWay logo

What is Appy.Flurl?

Flurl HTTP client library extensions for NETCore and NET 5.0.

Json Serializers

Package Latest Stable
Flurl.Serialization.TextJson Nuget Package

Table of Contents

Flurl System.Text.Json Serializer

Flurl have a default JsonSerialization implementation registered globally using NewtonsoftJsonSerializer, but you can change it for any other implementation.

Installing

Install using the Flurl.Serialization.TextJson NuGet package:

PM> Install-Package Flurl.Serialization.TextJson

Usage

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>();
    }
}

Contribute

It would be awesome if you would like to contribute code or help with bugs. Just follow the guidelines CONTRIBUTING