Variables
A comprehensive C# wrapper class for managing variables through HTTP API calls
Configure Configure API url
public static void <JsonElement> Configure(string apiUrl)
Specify a custom API url.
âŠī¸ Returns
void
đĄ Example
Variables.Configure("https://prod-api.mycompany.com")
GET GetVariableAsync
public async Task<JsonElement> GetVariableAsync(string name)
Retrieves a specific variable by its name from the API.
đ Parameters
name (string) - The name of the variable to retrieve
âŠī¸ Returns
Task<JsonElement?> - The retrieved variable data, or null if not found
đĄ Example
var variable = await Variables.GetVariableAsync("myVariable");
if (variable.HasValue)
{
Console.WriteLine($"Variable found: {variable.Value}");
}
else
{
Console.WriteLine("Variable not found");
}
GET GetAllVariablesAsync
public async Task<JsonElement> GetAllVariablesAsync()
Retrieves all variables from the API.
âŠī¸ Returns
Task<JsonElement> - All variables data as a JSON element
đĄ Example
var allVariables = await Variables.GetAllVariablesAsync();
var variableArray = allVariables.EnumerateArray();
foreach (var variable in variableArray)
{
foreach (var prop in variable.EnumerateObject())
{
Console.WriteLine($"{prop.Name}: {prop.Value}");
}
}
POST CreateVariableAsync
public async Task<JsonElement> CreateVariableAsync(object data)
Creates a new variable with the specified data.
đ Parameters
data (object) - The variable data to create. Can be any serializable object.
âŠī¸ Returns
Task<JsonElement> - The created variable data returned from the API
đĄ Example
var newVariable = new
{
name = "temperature",
value = "25.5",
type = "number"
};
var result = await Variables.CreateVariableAsync(newVariable);
Console.WriteLine($"Created variable: {result}");
PUT UpdateVariableAsync
public async Task<JsonElement> UpdateVariableAsync(string name, object newValue)
Updates an existing variable with a new value.
đ Parameters
name (string) - The name of the variable to update
newValue (object) - The new value for the variable
âŠī¸ Returns
Task<JsonElement> - The updated variable data returned from the API
đĄ Example
// Update a variable with a new value
var result = await Variables.UpdateVariableAsync("temperature", "30.2");
Console.WriteLine($"Updated variable: {result}");
đ¤ Request Body Structure
The method automatically wraps the new value in a JSON object:
{
"value": <newValue>
}