---
title: HttpClientBase
summary: API reference for HttpClientBase.
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data.Guidewire
reference_type: package
---

# HttpClientBase

Abstract base class shared by every Guidewire data-api client (`ActivityDataApiClient`, `ClaimDataApiClient`, `FinancialDataApiClient`, `ProviderDataApiClient`, `WorkerDataApiClient`). It owns the underlying `HttpClient`, resolves the client's base address from environment configuration, lazily attaches Basic authentication headers on first use, and provides cached/uncached GET and POST helpers that subclasses call to reach the Guidewire REST APIs. It depends on `IEnvironmentService` for configuration and secure credential lookup, `IDataClientConfiguration` for system identity and cache settings, and an optional Polly `IReadOnlyPolicyRegistry<string>` for response caching.

## Purpose
- Centralizes base-address resolution, Basic authentication, and cached/uncached HTTP GET/POST plumbing so concrete Guidewire clients only need to implement their route-specific methods.
- Defers authentication header creation until the first outbound call (`Client` getter), rather than at construction.

## Context
- Namespace: `SAIF.Data.Guidewire.Clients`
- Assembly/package: `SAIF.Data.Guidewire` (packaged in `SAIF.SAIFCode.Core`)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| Client | `protected HttpClient Client { get; }` | Returns the underlying `HttpClient`, triggering [SDG-BR-002](../../business-rules.md#sdg-br-002-basic-credentials-read-from-secure-configuration) Basic-auth header initialization on first access if not already retrieved |
| UrlKey | `protected abstract string UrlKey { get; }` | Environment configuration key subclasses must supply to resolve the API's base URL, used per [SDG-BR-001](../../business-rules.md#sdg-br-001-base-url-resolved-from-environment-configuration) |
| AuthKey | `protected abstract string AuthKey { get; }` | Environment secure-configuration key subclasses must supply to look up Basic auth credentials; an empty/whitespace value skips authentication header setup |
| HttpClientBase(IEnvironmentService, HttpClient, SystemType, string) | `[Obsolete] protected HttpClientBase(IEnvironmentService environmentService, HttpClient client, SystemType systemType, string baseUrlOverride)` | Obsolete constructor that forwards to the primary constructor using a new `DataClientConfiguration` with the given `SystemType` and `UseCache = false`; ignores `baseUrlOverride` |
| HttpClientBase(IEnvironmentService, HttpClient, IDataClientConfiguration, IReadOnlyPolicyRegistry\<string\>) | `protected HttpClientBase(IEnvironmentService environmentService, HttpClient client, IDataClientConfiguration configuration, IReadOnlyPolicyRegistry<string> policyRegistry)` | Primary constructor; resolves the cache policy (from the registry when `UseCache` is true, otherwise a Polly `NoOpAsync`), resolves the base URL via [SDG-BR-001](../../business-rules.md#sdg-br-001-base-url-resolved-from-environment-configuration), and assigns it to `client.BaseAddress` |
| GetAsyncCached\<T\>(string, bool, CancellationToken) | `protected Task<T> GetAsyncCached<T>(string url, bool ensureSuccess = false, CancellationToken cancellationToken = default)` | Executes a GET through the configured Polly cache policy per [SDG-BR-003](../../business-rules.md#sdg-br-003-responses-cached-unless-caching-is-disabled) and deserializes the response body as `T` using Newtonsoft.Json, returning `default` for empty content |
| GetAsync(string, bool, CancellationToken) | `protected Task<string> GetAsync(string url, bool ensureSuccess = false, CancellationToken cancellationToken = default)` | Issues an uncached GET against `Client` and returns the raw response body as a string |
| GetAsyncCached\<T\>(string, string, bool, CancellationToken) | `protected Task<T> GetAsyncCached<T>(string url, string body, bool ensureSuccess = false, CancellationToken cancellationToken = default)` | Executes a POST with the given JSON body through the configured Polly cache policy per [SDG-BR-003](../../business-rules.md#sdg-br-003-responses-cached-unless-caching-is-disabled) and deserializes the response as `T` |

## Behavioral notes
- `InitializeClientAuthorization` (private) computes the system hash via `SystemHashUtil.ComputeHash(SystemType, SystemName)` when `SystemName` is set, otherwise `SystemHashUtil.Get(SystemType)`, then splits the secure setting on `|` into username/password and adds a Base64-encoded `Authorization: Basic` header, per [SDG-BR-002](../../business-rules.md#sdg-br-002-basic-credentials-read-from-secure-configuration).
- When `ensureSuccess` is true and the response is not a success status code, `GetContent` (private) calls `response.EnsureSuccessStatusCode()`, which throws `HttpRequestException`.
- The obsolete constructor always disables caching (`UseCache = false`) and silently ignores any `baseUrlOverride` value passed by the caller.
- Cache keys are built from `{typeof(T).FullName}-{url}-{ensureSuccess}` plus an appended body hash code when a request body is present; this is used only when `UseCache` is true and a policy registry was supplied.

## Constraints and usage notes
- Concrete subclasses must implement `UrlKey` and `AuthKey`; a null or empty `UrlKey` will cause `Uri` construction to fail at construction time.
- The `Client`, `GetAsync`, and `GetAsyncCached<T>` members are `protected`, so they are usable only from within derived classes, not directly by external callers.
- If `UseCache` is true but no `policyRegistry` is supplied, the cache policy falls back to `Policy.NoOpAsync()`, effectively disabling caching despite `UseCache` being true.

## Sources
- `Data/SAIF.Data.Guidewire/Clients/HttpClientBase.cs`
