General Configuration
Since version 3.0 RestClient supports granular configuration of the underline HttpClient via the Config class and it’s Pipeline.
From version 3.3.0 we support configuration of the HttpClient Pipeline using IHttpClientFactory.
General config is just done by setting properties on the Config object.
When directly creating a RestClient instance pass the Config object to the constructor:
var config = new Config
{
//HttpClient request timeout https://msdn.microsoft.com/en-us/library/system.net.http.httpclient.timeout(v=vs.118).aspx
Timeout = TimeSpan.FromSeconds(10.0),
//HttpClient MaxResponseContentBufferSize https://msdn.microsoft.com/en-us/library/system.net.http.httpclient.maxresponsecontentbuffersize(v=vs.118).aspx
MaxResponseContentBufferSize = 1000,
//Whether to use the DefaultJsonHandler which is added to the beginning of Pipeline by default
UseDefaultHandlers = false
};
var restClient = new RestClient("http://jsonplaceholder.typicode.com", config);
When using IHttpClientFactory use the ConfigureHttpClient extension method when adding the RestClient to your .NET Core DI container (usually in Startup.cs)
services.AddRestClient("http://jsonplaceholder.typicode.com")
.UseNoDefaultHandlers()
.HttpClientBuilder.ConfigureHttpClient(client =>
{
client.Timeout = TimeSpan.FromMinutes(1);
client.MaxResponseContentBufferSize = 1000;
});