Integrations

Chaining REST Calls: Results and Workflows

A single RESTClient instance can carry results from one call into the next -- by name, not by manual variable juggling -- and WithWorkflow/While/Until turn a sequence of calls into a repeatable loop.

AndThen and Named Results

AndThen() (or AndThen<T>()) executes the current request and returns the same RESTClient for another WithEndpoint call, so a sequence of dependent requests reads as one chain. WithResultName("name") labels the result of the next Execute/AndThen so later calls can reference it. WithParametersFromResult, WithUrlFromResult, WithTextFromResult, and similar FromResult methods pull a named (or positionally indexed) prior result directly into the next request's settings.

var client = GPAL.RESTClient

.WithAPIBase("https://api.example.com")

.WithEndpoint("/v1/customers/42")

.WithResultName("customer")

.AndThen()

.WithEndpoint("/v1/orders")

.WithParametersFromResult("customer")

.Execute();

Reading Back Results

GetExecutionResults() returns a ResultCollection holding every named result produced by the chain so far. Results["customer"] returns the most recent result stored under that name, cast to the expected type since the collection itself is not generic. Workflows (below) can reuse the same result name on every pass, so ResultCollection also tracks which iteration each result came from.

var results = client.GetExecutionResults();

string customerName = (string)results["customer"];

Workflows: While and Until

WithWorkflow(c => ...) records a sequence of calls as a named block without running it yet. While(condition) then repeats that block for as long as the condition holds (capped at 1000 iterations as a safety limit); Until(condition) repeats until the condition becomes true. Each iteration starts the workflow's calls from the same configuration they had when WithWorkflow was defined, so it's a clean repeat rather than a continuation of the previous iteration's chain. If every pass uses the same WithResultName("name"), each pass's result is kept rather than overwritten. Read one pass back with results["name", iteration], or every pass at once with results.GetAllResults("name").

int page = 0;

var client = GPAL.RESTClient

.WithAPIBase("https://api.example.com")

.WithWorkflow(c => c

.WithEndpoint("/v1/items")

.WithParameters(new { page = ++page })

.WithResultName("items")

.Execute())

.Until(() => page >= 5);

var results = client.GetExecutionResults();

object firstPage = results["items", 0];

var allPages = results.GetAllResults("items");