Class NovaRazorHttpClientFactory
A factory class providing pooled/cached HttpClients for external API endpoints. To be registered as a scoped instance in the DI container.
Inherited Members
Namespace: Noxum.Nova.Razor.Model
Assembly: Noxum.Nova.Razor.Model.dll
Syntax
public class NovaRazorHttpClientFactory
Constructors
NovaRazorHttpClientFactory(INovaExternalApiClients)
A factory class providing pooled/cached HttpClients for external API endpoints. To be registered as a scoped instance in the DI container.
Declaration
public NovaRazorHttpClientFactory(INovaExternalApiClients externalApiClients)
Parameters
| Type | Name | Description |
|---|---|---|
| INovaExternalApiClients | externalApiClients |
Fields
UserHeaderName
Name of the header that carries the acting user for External API calls (CMS API convention).
Declaration
public const string UserHeaderName = "X-CmsApi-Username"
Field Value
| Type | Description |
|---|---|
| string |
Methods
ApplyEndpoint(HttpRequestHeaders, CachedExternalApi, bool, string)
Set authentication and host headers appropriately
Declaration
public static void ApplyEndpoint(HttpRequestHeaders headers, CachedExternalApi endpoint, bool overrideUserHeader = false, string userName = null)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpRequestHeaders | headers | |
| CachedExternalApi | endpoint | |
| bool | overrideUserHeader | For CMS API endpoints, replace any user header already present with |
| string | userName | The name of the acting user, if any. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException |
GetHttpClientAsync(CachedExternalApi)
Create and return the appropriate, disposable HttpClient for the given external API. This will use cached handlers as far as possible.
Declaration
public Task<HttpClient> GetHttpClientAsync(CachedExternalApi externalApi)
Parameters
| Type | Name | Description |
|---|---|---|
| CachedExternalApi | externalApi |
Returns
| Type | Description |
|---|---|
| Task<HttpClient> |