HttpClientBuilder 0.0.1
See the version list below for details.
dotnet add package HttpClientBuilder --version 0.0.1
NuGet\Install-Package HttpClientBuilder -Version 0.0.1
<PackageReference Include="HttpClientBuilder" Version="0.0.1" />
paket add HttpClientBuilder --version 0.0.1
#r "nuget: HttpClientBuilder, 0.0.1"
// Install HttpClientBuilder as a Cake Addin #addin nuget:?package=HttpClientBuilder&version=0.0.1 // Install HttpClientBuilder as a Cake Tool #tool nuget:?package=HttpClientBuilder&version=0.0.1
<img src="./docs/http_logo.png" alt="drawing" width="100"/>
HTTP Client Builder
Client builder is a configuration builder for HTTP request piplines. The client builder can be used to create http clients configured against API models using an expressive and fluent API.
var client = ClientBuilder.CreateBuilder()
.WithHost("172.26.6.104")
.WithBaseRoute("api/weather")
.WithBearerToken("JWT TOKEN HERE")
.WithSelfSignedCerts()
.WithHeader("x-api-key", "this is an extra header")
.BuildClient();
public async Task<bool> ExampleGetWeatherAndCheckIfItsNice()
{
var response = await client
.GetContentAsync<Weather>("weather")
.EnsureAsync(
predicate: (weather) => weather.IsNice && weather.Temperature > 60,
errorFactory: () => new Exception("THE WEATHER IS NOT NICE"))
.HandleAsync(
value: (code, weather) =>
{
//PROCESS WEATHER ONLY IF THE WEATHER IS NICE AND GREATER THAN 60
},
error: (exception) =>
{
//PROCESS ERROR ONLY IF THE REQUEST FAILED OR THE WEATHER IS NOT NICE
});
return response.Success;
}
Table of Contents
Building
To begin using the IHttpClient
interface the ClientBuilder
must be used. Begin the build pipline by involing the ClientBuilder.CreateBuilder()
static factory. This will return an IClientBuilder
interface directing consumers through
each step of the build pipeline.
Configure Host Settings
The first step in the client builder pipline requires a host configuration.
The ConfigureHost
method requires an IPADRESS OR HOSTNAME as the first required parameter.
IHttpClient client = ClientBuilder.CreateBuilder()
.WithHost("172.26.6.104")
.CreateClient();
You can optionally provide a HttpScheme
of either https or http. If no scheme is provided the builder will default to HTTPS
IHttpClient client = ClientBuilder.CreateBuilder()
.WithHost("172.26.6.104", scheme: HttpScheme.Http)
.CreateClient();
An optional PORT can also be provided to specify a TCP port used by the HTTP or HTTPS server.
IHttpClient client = ClientBuilder.CreateBuilder()
.WithHost("172.26.6.104", scheme: HttpScheme.Http, port: 15672)
.CreateClient();
After configuring a host the builder will proceed to either the CreateClient()
or Authorization
steps.
Configure Authorization
The client builder support several authentication steps such as: Basic Auth, Beaer Token, Api Keys, and finally an optional Factory.
To add a default authorization bearer token to the client, invoke the
ConfigureBearerToken(token)
method. The provided token will be added to all
requests an Authorization: Bearer Token... header.
IHttpClient client = ClientBuilder.CreateBuilder()
.WithHost("172.26.6.104")
.WithBearerToken("JWT TOKEN HERE")
.CreateClient();
Expressions
Requests
Responses
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Text.Json (>= 7.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Client builder is a configuration builder for HTTP request piplines. The client builder can be used to create http clients configured against API models using an expressive and fluent API.