---
title: GetResult<T>
summary: Retrieve a single typed value from a GET call, with type-specific coercion.
status: draft
owner: bendy
last_reviewed: 2026-09-15
library: SAIF.Web.API.Clients
reference_type: package
operation_id: OP-01
trigger: Direct call by a consuming application
---

# GetResult<T>

`GetResult<T>` issues a GET request through the shared HTTP funnel and materializes a single value of type `T`, applying type-specific coercion rules so callers never have to hand-write conversion code for primitives, strings, or byte arrays.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-01 |
| **Trigger** | Direct call by a consuming application. |
| **Inputs** | `methodUriSegment` (relative URI appended to the service base URI); generic type argument `T`. |
| **Outputs** | A single `T`, or `default(T)`. |
| **Primary components** | `JsonHttpClient.GetResult<T>(string)` |
| **Entry point** | `src/SAIF.Web.API.Clients/JsonHttpClient.cs` |

## Steps

1. Execute the HTTP GET through the shared request funnel.
   - Embedded logic ([BR-CLI-001](../business-rules.md#br-cli-001-ntlm-default-authentication), [BR-CLI-002](../business-rules.md#br-cli-002-caller-identity-headers-required), [BR-CLI-003](../business-rules.md#br-cli-003-on-behalf-of-user-forwarding), [BR-CLI-005](../business-rules.md#br-cli-005-transient-failure-retry), [BR-CLI-006](../business-rules.md#br-cli-006-non-success-response-failure-conversion), [BR-CLI-010](../business-rules.md#br-cli-010-per-client-request-timeout), [BR-CLI-011](../business-rules.md#br-cli-011-date-time-zone-handling-consistency)):
     - Build the RestSharp client, assign the authenticator, clear default content handlers, and add identity/on-behalf-of-user headers.
     - Execute the request, retry on a configured status set, and enforce success before returning.

   > **Origin**: This step is implemented in [GetJsonResponse](get-json-response.md) (`SAIF.Web.API.Clients`) and executed on behalf of this operation.
   - On failure: any non-success status surfaces as a `SAIF.API.Exceptions.SAIFException` subclass from the delegate.
2. If `T` is `string`: trim surrounding `"` quotes from the raw content and `Convert.ChangeType` to `T` ([BR-CLI-013](../business-rules.md#br-cli-013-single-value-result-coercion)).
   - Returns immediately; no JSON parse is performed.
3. Else if `T.IsPrimitive`: `Convert.ChangeType(content, typeof(T))` on the raw, untrimmed content ([BR-CLI-013](../business-rules.md#br-cli-013-single-value-result-coercion)).
   - On failure: a malformed or quoted primitive payload throws `FormatException`/`InvalidCastException` uncaught to the caller.
4. Else if `T` is `byte[]`: trim `"` and `Convert.FromBase64String` ([BR-CLI-013](../business-rules.md#br-cli-013-single-value-result-coercion)).
   - On failure: non-base64 content throws `FormatException` uncaught.
5. Else if content is `null` or the literal string `"null"`: return `default(T)` ([BR-CLI-013](../business-rules.md#br-cli-013-single-value-result-coercion)).
   - Short-circuits deserialization.
6. Else: deserialize to `T[]` via `GetContentArray<T>` and return element `[0]` ([BR-CLI-012](../business-rules.md#br-cli-012-response-payload-shape-normalization)).
   - Embedded logic:
     - Normalize the JSON payload shape (array, object, or scalar) into `T[]`.

   > **Origin**: This step is implemented in [GetContentArray\<T\>](get-content-array.md) (`SAIF.Web.API.Clients`) and executed on behalf of this operation.
   - On failure: wrapped in `catch (InvalidCastException) → return default(T)`. An empty result array throws `IndexOutOfRangeException`, which this catch does not handle*.

## Process flow

The following diagrams visualize this operation's control flow, split by concern so each renders at a readable width.

The first diagram shows the `string` and `primitive` type-check branches:

```mermaid
flowchart TD
	Start(["GetResult&lt;T&gt;<br>called"]) --> Funnel["Execute GET via<br>GetJsonResponse"]
	Funnel --> TypeCheck{Type of T?}
	TypeCheck -->|string| Trim["Trim quotes,<br>Convert.ChangeType"] --> EndOk([Return T])
	TypeCheck -->|primitive| Convert["Convert.ChangeType on<br>raw content"] --> EndOk
```

The second diagram shows the `byte array` and `null` type-check branches:

```mermaid
flowchart TD
	TypeCheck{Type of T?} -->|byte array| Base64["Trim quotes,<br>FromBase64String"] --> EndOk([Return T])
	TypeCheck -->|null / literal null| Default[Return default T] --> EndOk
```

The third diagram shows the fallback (`other`) type-check branch:

```mermaid
flowchart TD
	TypeCheck{Type of T?} -->|other| Deserialize["GetContentArray, take<br>element 0"] --> EndOk([Return T])
```

## Failure and edge-case behavior
- A malformed or quoted primitive payload throws `FormatException`/`InvalidCastException` uncaught to the caller (step 3).
- Non-base64 content for a `byte[]` target throws `FormatException` uncaught (step 4).
- An empty result array from `GetContentArray<T>` raises `IndexOutOfRangeException`, which the surrounding `catch (InvalidCastException)` does not handle*.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

> **Note:** Statements marked with `*` were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts.

## Sources
- `src/SAIF.Web.API.Clients/JsonHttpClient.cs`
