Fluent Pipeline Extensions
I’ve created extension methods to make managing the pipeline look a bit prettier.
Example when directly creating a RestClient instance:
var config = new Config() //Build a pipeline using extension methods
.UseHttpClientHandler(new HttpClientHandler())
.UseHandler((request, token, next) => next(request, token))
.UseHandler(new UnitTestHandler())
.UseUnitTestHandler(request => { })
.UseUnitTestHandler(request => new HttpResponseMessage());
dynamic restClient = new RestClient("http://headers.jsontest.com/", config);
Example when using IHttpClientFactory to add the RestClient to your .NET Core DI container (usually in Startup.cs):
services
.AddRestClient("http://headers.jsontest.com/")
.UseHttpClientHandler(() => new HttpClientHandler())
.UseHandler((request, token, next) => next(request, token))
.UseHandler(()=>new UnitTestHandler())
.UseUnitTestHandler(request => { })
.UseUnitTestHandler(request => new HttpResponseMessage());
Note IHttpClientFactory can only use extension methods for it’s pipeline configuration