Skip to content

Providers

Stanislav Molchanovskiy edited this page Dec 1, 2021 · 5 revisions

Providers give additional implementations for sending HTTP requests, serialization, and resilience. You can use the providers listed below or implement your own.

NClient.Providers.Api.Rest

The package NClient.Providers.Api.Rest implements the conversion of an interface method call into a REST request. This package is included in the NClient package dependencies and is the default provider for REST clients. To use this provider, you need to call the UsingRestApi method when building a client.

NClient.Providers.Transport.SystemNetHttp

The package NClient.Providers.Transport.SystemNetHttp implements transport to the endpoint for requests over HTTP using System.Net.Http. This package is included in the NClient package dependencies and is the default provider for the HTTP transport implementation. To use this provider, you need to call the UsingSystemNetHttpTransport method (or its alias UsingHttpTransport) when building a client.

NClient.Providers.Transport.RestSharp

The package NClient.Providers.Transport.RestSharp implements transport to the endpoint for requests over HTTP using the RestSharp library. This can be useful, for example, to switch from the RestSharp library to NClient - you can return standard RestSharp (IRestResponse) responses from client interface methods. To use RestSharp client instead of the default one, you need to install package and use the UsingRestSharpTransport method:

IMyClient myClient = NClientGallery.Clients.GetRest()
    .For<IMyClient>(host: "http://localhost:8080")
    .UsingRestSharpTransport()
    .Build();

Keep in mind that RestSharp uses legacy HttpWebRequest, so it won't work in Blazor.

NClient.Providers.Serialization.SystemTextJson

The package NClient.Providers.Serialization.SystemTextJson implements JSON serialization using System.Text.Json. This package is included in the NClient package dependencies and is the default provider for the serialization implementation. To use this provider, you need to call the UsingSystemTextJsonSerialization method (or its alias UsingJsonSerializer) when building a client.

NClient.Providers.Serialization.NewtonsoftJson

The package NClient.Providers.Serialization.NewtonsoftJson implements JSON serialization using Newtonsoft.Json. This package will be useful if you need deserialization of generics or some Newtonsoft functionality. If you want to use Newtonsoft.Json for serialization, you need to install package and use the UsingNewtonsoftJsonSerialization method:

IMyClient myClient = NClientGallery.Clients.GetRest()
    .For<IMyClient>(host)
    .UsingNewtonsoftJsonSerialization()
    .Build();

NClient.Providers.Serialization.SystemXml

The package NClient.Providers.Serialization.SystemXml implements XML serialization using System.Xml.Serialization. If you want to use System.Xml.Serialization for serialization, you need to install package and use the WithSystemXmlSerialization method:

IMyClient myClient = NClientGallery.Clients.GetRest()
    .For<IMyClient>(host)
    .WithSystemXmlSerialization()
    .Build();

NClient.Providers.Serialization.MessagePack

The package NClient.Providers.Serialization.MessagePack implements MessagePack serialization using MessagePackCSharp. If you want to use MessagePack for serialization, you need to install package and use the WithMessagePackSerialization method:

IMyClient myClient = NClientGallery.Clients.GetRest()
    .For<IMyClient>(host)
    .WithMessagePackSerialization()
    .Build();

NClient.Providers.Serialization.ProtobufNet

The package NClient.Providers.Serialization.ProtobufNet implements ProtobufNet serialization using ProtobufNet. If you want to use ProtobufNet for serialization, you need to install package and use the WithProtobufNetSerialization method:

IMyClient myClient = NClientGallery.Clients.GetRest()
    .For<IMyClient>(host)
    .WithProtobufNetSerialization()
    .Build();

NClient.Providers.Resilience.Polly

The package NClient.Providers.Resilience.Polly implements resilience for client method calls. This package is included in the NClient package dependencies and is the default provider for resilience. To use this provider, you need to call the WithPolly* method and other with the prefix Polly.

NClient.Providers.Mapping.HttpResponses

The package NClient.Providers.Mapping.HttpResponses implements mapping to a set of models representing HTTP responses with deserialized data that can be used as return types of client methods. This package is included in the NClient and the mapper from the package is already in the client. To use this provider for custom clients, you need to call the WithResponseToHttpResponseMapping method when building a client.

NClient.Providers.Mapping.LanguageExt

The package NClient.Providers.Mapping.LanguageExt implements mapping to a set of monads from LanguageExt library that can be used as return types of client methods. To use this provider, you need to call the WithResponseToMonadMapping method when building a client.