Skip to content

GetResult

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.
  2. Embedded logic (BR-CLI-001, BR-CLI-002, BR-CLI-003, BR-CLI-005, BR-CLI-006, BR-CLI-010, BR-CLI-011):
    • 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 (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). - 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). - 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). - 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). - Short-circuits deserialization. 6. Else: deserialize to T[] via GetContentArray<T> and return element [0] (BR-CLI-012). - Embedded logic: - Normalize the JSON payload shape (array, object, or scalar) into T[].

Origin: This step is implemented in GetContentArray\<T> (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:

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:

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:

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*.

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