Library containing Http related classes such as base classes for connecting to Api's.
Create a custom Api Client class using the RestHttpClient class and HttpClientBuilder.
public class Example
{
public async Task CustomApiClientExample()
{
HttpClient httpClient = new HttpClientBuilder()
.WithDefaultHeaders()
.WithBearerAuthorisationHeader(new JwtBearerTokenGenerator(new MyClientConfiguration()))
.Build();
var restApiClient = new RestHttpClient(httpClient);
var result = await restApiClient.Get("http://some-host/some-resource/");
}
private class MyClientConfiguration : IJwtClientConfiguration
{
public string ClientToken { get => "SomeTokenValue"; }
}
}
This class builds a HttpClient with specified configuration:
Adds default headers such as Accept header.
Adds a handler that inherits from System.Net.Http.DelegatingHandler
Adds a Bearer header with the value provided by the implementation of IGenerateBearerToken
interface that is passed in. Currently two generators are provided:
JwtBearerTokenGenerator
AzureADBearerTokenGenerator