Skip to content

rixian/extensions-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rixian HttpClient Extensions

This library provides extension methods for setting up an HttpClient.

NuGet package codecov

Features

  • Configure Basic HttlClient properties, such as SSL Protocols.
  • Configure an ITokenClient as the source of the Authorization header.
  • Configure the Authorization header with a static Bearer token value.
  • Configure any header with a static value.

Usage

Use SSL Protocols

IServiceCollection services = ...;

services.AddHttpClient("test")
    .UseSslProtocols(SslProtocols.Tls12); // Sets the primary HttpClientHandler to use TLS 1.2

ITokenClient - Named

IServiceCollection services = ...;

services.AddTokenClient("tokenClient123", ...);

services.AddHttpClient("test")
    .AddTokenClient("tokenClient123"); // Adds the header "Authorization: Bearer {access_token}"

ITokenClient - DI Lookup

IServiceCollection services = ...;

services.AddTokenClient(...);

services.AddHttpClient("test")
    .AddTokenClient(svc =>
    {
        return svc
            .GetRequiredService<ITokenClientFactory>()
            .GetTokenClient();
    }); // Adds the header "Authorization: Bearer {access_token}"

ITokenClient - Direct Instance

IServiceCollection services = ...;

ITokenClient tokenClient = ...;

services.AddHttpClient("test")
    .AddTokenClient(tokenClient); // Adds the header "Authorization: Bearer {access_token}"

Static Bearer Token

IServiceCollection services = ...;

string bearerToken = "REPLACE_ME";

services.AddHttpClient("test")
    .AddBearerToken(bearerToken); // Adds the header "Authorization: Bearer REPLACE_ME"

Static Authorization Header

IServiceCollection services = ...;

string scheme = "HDR_SCHEME";
string parameter = "HDR_PARAM";

services.AddHttpClient("test")
    .AddAuthorizationHeader(scheme, parameter); // Adds the header "Authorization: HDR_SCHEME HDR_PARAM"

Static Header

IServiceCollection services = ...;

string name = "HDR_NAME";
string value = "HDR_VALUE";

services.AddHttpClient("test")
    .AddHeader(name, value); // Adds the header "HDR_NAME: HDR_VALUE"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published