HttpClientBuilder 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package HttpClientBuilder --version 0.0.1
NuGet\Install-Package HttpClientBuilder -Version 0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HttpClientBuilder" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HttpClientBuilder --version 0.0.1
#r "nuget: HttpClientBuilder, 0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

GitHub GitHub all releases Nuget GitHub issues GitHub Repo stars GitHub forks

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

Readme Image

Table of Contents

  1. Building Clients
  2. Expressions
  3. Requests
  4. Responses

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.3 256 11/12/2023
0.0.2 98 11/10/2023
0.0.1 96 11/9/2023

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.