Dynamic API

6 minute readAutomation

Our dynamic API is an alternative to the CloudBees Feature Management static API for defining flags on different container objects and accessing them from that container object. (See static API in Creating feature flags.)

Dynamic API allows you to get flags value by their name (String). If the flag does not exist, it creates the flag and returns the default value.

The dynamic API consist of 3 functions:

  • isEnabled - returns a boolean

  • value - returns a string

  • getNumber/getInt,getDouble - returns a number

getNumber/getInt,getDouble is only supported from SDKs version >= 5.0

Here is the example of how it is used:

JavaScript
JavaScript SSR
Java, Android
Python
Ruby
Go
.NET
PHP
C
C++
Objective C
Swift
/**
  isEnabled - getting boolean value of a flag
**/

var b1 = Rox.dynamicApi.isEnabled('system.reportAnalytics', false);
var b2 = Rox.dynamicApi.isEnabled('system.reportAnalytics', true);
var b3 = Rox.dynamicApi.isEnabled('system.reportAnalytics', false, context);


/**
  value - getting String value of a String flag
**/

var s1 = Rox.dynamicApi.value('ui.textColor', "red");
var s2 = Rox.dynamicApi.value('ui.textColor', "green");
var s3 = Rox.dynamicApi.value('ui.textColor', "red", context);

/**
  getNumber - getting number value of a number flag
**/
var s1 = Rox.dynamicApi.getNumber('ui.textSize', 12);
var s2 = Rox.dynamicApi.getNumber('ui.textSize', 14);
var s3 = Rox.dynamicApi.getNumber('ui.textColor', 18, context);
import {Rox} from 'rox-ssr';

/**
  isEnabled - getting boolean value of a flag
**/

var b1 = Rox.dynamicApi.isEnabled('system.reportAnalytics', false);
var b2 = Rox.dynamicApi.isEnabled('system.reportAnalytics', true);
var b3 = Rox.dynamicApi.isEnabled('system.reportAnalytics', false, context);


/**
  value - getting String value of a Variant flag
**/

var s1 = Rox.dynamicApi.value('ui.textColor', "red");
var s2 = Rox.dynamicApi.value('ui.textColor', "green");
var s3 = Rox.dynamicApi.value('ui.textColor', "red", context);

/**
  getNumber - getting number value of a number flag
**/
var s1 = Rox.dynamicApi.getNumber('ui.textSize', 12);
var s2 = Rox.dynamicApi.getNumber('ui.textSize', 14);
var s3 = Rox.dynamicApi.getNumber('ui.textColor', 18, context);
/**
  isEnabled - getting boolean value of a flag
**/

boolean b1 =  Rox.dynamicAPI().isEnabled("system.reportAnalytics", false);
boolean b2 = Rox.dynamicAPI().isEnabled("system.reportAnalytics", true);
boolean b3 =  Rox.dynamicAPI().isEnabled("system.reportAnalytics", false, context);


/**
  value - getting String value of a flag
**/

String s1 = Rox.dynamicAPI().getValue(("ui.textColor", "red", new String[]{"red", "green", "blue"} );
String s2 = Rox.dynamicAPI().getValue("ui.textColor", "green", new String[]{"red", "green", "blue"} );
String s3 = Rox.dynamicAPI().getValue("ui.textColor", "red", new String[]{"red", "green", "blue"}, context );

/**
  getInt - getting Integer value of a flag
 **/

int i1 = Rox.dynamicAPI().getInt("font.size", 2, new int[]{ 1, 2, 3 });
int i2 = Rox.dynamicAPI().getInt("font.size", 3, new int[]{ 1, 2, 3 });
int i3 = Rox.dynamicAPI().getInt("font.size", 2, new int[]{ 1, 2, 3 }, context);

/**
  getDouble - getting double value of a flag
 **/

double d1 = Rox.dynamicAPI().getDouble("demo.double", 2.2, new int[]{ 1.1, 2.2, 3.3 });
double d2 = Rox.dynamicAPI().getDouble("demo.double", 3.3, new int[]{ 1.1, 2.2, 3.3 });
double d3 = Rox.dynamicAPI().getDouble("demo.double", 2.2, new int[]{ 1.1, 2.2, 3.3 }, context);
#/**
#  is_enabled - getting boolean value of a flag
#**/

b1 = Rox.dynamic_api().is_enabled('default.newFlag', False)
b2 = Rox.dynamic_api().is_enabled('default.newFlag', True)
b3 =  Rox.dynamic_api().is_enabled('default.newFlag', True, context)


#/**
#  get_value - getting String value of a String flag
#**/

s1 = Rox.dynamic_api().get_value('ui.text_color', 'red', ['red', 'green', 'blue'])
s2 = Rox.dynamic_api().get_value('ui.text_color', 'green', ['red', 'green', 'blue'])
s3 = Rox.dynamic_api().get_value('ui.text_color', 'red', ['red', 'green', 'blue'], context)

#/**
#  get_int - getting int value of a int flag
#**/

s1 = Rox.dynamic_api().get_int('ui.text_size', 12, [14, 18, 24])
s2 = Rox.dynamic_api().get_int('ui.text_size', 24, [14, 18, 24])
s3 = Rox.dynamic_api().get_int('ui.text_size', 12, [14, 18, 24], context)

#/**
#  get_double - getting double value of a double flag
#**/

s1 = Rox.dynamic_api().get_double('math.special_numbers', 3.14, [2.71, 0.577])
s2 = Rox.dynamic_api().get_double('math.special_numbers', 2.71, [2.71, 3.14, 0.577])
s3 = Rox.dynamic_api().get_double('math.special_numbers', 3.14, [2.71, 0.577], context)
require 'rox/server/rox_server'
# isEnabled - getting boolean value of a flag

# calling flag default.newFlag
# if experiment doens't exist return false
b1 = Rox::Server::RoxServer.dynamic_api.enabled?('default.newFlag', false)
# if experiment doens't exist return true
b2 = Rox::Server::RoxServer.dynamic_api.enabled?('default.newFlag', true)
# pass context to the flag evaluation
b3 = Rox::Server::RoxServer.dynamic_api.enabled?('default.newFlag', true, context)

# value - getting String value of a Variant flag

# Calling without context (nil), default 'A', variants: 'A', 'B' or 'C'
s1 = Rox::Server::RoxServer.dynamic_api.value('def.newVariant', 'A', nil, ['A', 'B', 'C'])

# Calling with context
s2 = Rox::Server::RoxServer.dynamic_api.value('def.newVariant', 'A', context, ['A', 'B', 'C'])
b1 := rox.DynamicAPI().IsEnabled('default.newFlag', false, nil)
b2 := rox.DynamicAPI().IsEnabled('default.newFlag', True, nil)
b3 := rox.DynamicAPI().IsEnabled('default.newFlag', True, context)


s1 := rox.DynamicAPI().GetValue('ui.text_color', 'red', ['red', 'green', 'blue'], nil)
s2 := rox.DynamicAPI().GetValue('ui.text_color', 'green', ['red', 'green', 'blue'], nil)
s3 := rox.DynamicAPI().GetValue('ui.text_color', 'red', ['red', 'green', 'blue'], context)



s1 := rox.DynamicAPI().GetInt('ui.text_size', 12, [14, 18, 24], nil)
s2 := rox.DynamicAPI().GetInt('ui.text_size', 24, [14, 18, 24], nil)
s3 := rox.DynamicAPI().GetInt('ui.text_size', 12, [14, 18, 24], context)


s1 := rox.DynamicAPI().GetDouble('math.special_numbers', 3.14, [2.71, 0.577], nil)
s2 := rox.DynamicAPI().GetDouble('math.special_numbers', 2.71, [2.71, 3.14, 0.577], nil)
s3 := rox.DynamicAPI().GetDouble('math.special_numbers', 3.14, [2.71, 0.577], context)
/**
  IsEnabled - getting boolean value of a flag
**/

var b1 = Rox.DynamicApi().IsEnabled("system.reportAnalytics", false);
var b2 = Rox.DynamicApi().IsEnabled("system.reportAnalytics", true);
var b3 = Rox.DynamicApi().IsEnabled("system.reportAnalytics", false, context);


/**
  GetValue - getting String value of a string flag
**/

var s1 = Rox.DynamicApi().GetValue("ui.textColor", "red", new[] {"red", "green", "blue"});
var s2 = Rox.DynamicApi().GetValue("ui.textColor", "green", new[] {"red", "green", "blue"});
var s3 = Rox.DynamicApi().GetValue("ui.textColor", "red", new[] {"red", "green", "blue"}, context);


/**
  GetInt - getting int value of a int flag
**/

var s1 = Rox.DynamicApi().GetInt("ui.textSize", 12, new[] {14, 18, 24});
var s2 = Rox.DynamicApi().GetInt("ui.textSize", 24, new[] {14, 18, 24});
var s3 = Rox.DynamicApi().GetInt("ui.textSize", 12, new[] {14, 18, 24}, context);


/**
  GetDouble - getting double value of a double flag
**/

var s1 = Rox.DynamicApi().GetDouble("math.specialNumbers", 3.14, new[] { 2.71, 0.577 });
var s2 = Rox.DynamicApi().GetDouble("math.specialNumbers", 2.71, new[] { 2.71, 3.14, 0.577 });
var s3 = Rox.DynamicApi().GetDouble("math.specialNumbers", 3.14, new[] { 2.71, 0.577 }, context);
$report1 = Rox::dynamicApi()->isEnabled("system.reportAnalytics", false);

$report2 = Rox::dynamicApi()->isEnabled("system.reportAnalytics", true);

$report3 = Rox::dynamicApi()->isEnabled("system.reportAnalytics", false, $context);


$color1 = Rox::dynamicApi()->getValue("ui.textColor", "red", ["red", "green", "blue"]);

$color2 = Rox::dynamicApi()->getValue("ui.textColor", "green", ["red", "green", "blue"]);

$color3 = Rox::dynamicApi()->getValue("ui.textColor", "blue", ["red", "green", "blue"], $context);
RoxDynamicApi *dynamic = rox_dynamic_api();

/* boolean flag - is enabled */

bool report1 = rox_dynamic_api_is_enabled(dynamic, "system.reportAnalytics", false);

bool report2 = rox_dynamic_api_is_enabled(dynamic, "system.reportAnalytics", true);

bool report3 = rox_dynamic_api_is_enabled_ctx(dynamic, "system.reportAnalytics", false, context);

/* getting value of a string flag named ui.textColor */

char *color1 = rox_dynamic_api_get_string_ctx(dynamic, "ui.textColor", "red", ROX_LIST_COPY_STR("red", "blue", "green"), NULL);

char *color2 = rox_dynamic_api_get_string_ctx(dynamic, "ui.textColor", "green", ROX_LIST_COPY_STR("red", "blue", "green"), NULL);

char *color3 = rox_dynamic_api_get_string_ctx(dynamic, "ui.textColor", "blue", ROX_LIST_COPY_STR("red", "blue", "green"), context);

/* getting int value of a int flag */

int n1 = rox_dynamic_api_get_int_ctx(dynamic, "ui.textSize", 12, ROX_INT_LIST(14, 18, 24), NULL);

int n2 = rox_dynamic_api_get_int_ctx(dynamic, "ui.textSize", 24, ROX_INT_LIST(14, 18, 24), NULL);

int n3 = rox_dynamic_api_get_int_ctx(dynamic, "ui.textSize", 12, ROX_INT_LIST(14, 18, 24), context);

/* getting double value of a double flag */

double d1 = rox_dynamic_api_get_double_ctx(dynamic, "math.specialNumbers", 3.14, ROX_DBL_LIST(2.71, 0.577), NULL);

double d2 = rox_dynamic_api_get_double_ctx(dynamic, "math.specialNumbers", 2.71, ROX_DBL_LIST(2.71, 3.14, 0.577), NULL);

double d3 = rox_dynamic_api_get_double_ctx(dynamic, "math.specialNumbers", 3.14, ROX_DBL_LIST(2.71, 0.577), context);

rox_dynamic_api_free(dynamic);
Rox::DynamicApi *dynamic = Rox::DynamicApi::Create();

/* boolean flag - is enabled */

bool report1 = dynamic->IsEnabled("system.reportAnalytics", false);

bool report2 = dynamic->IsEnabled("system.reportAnalytics", true);

bool report3 = dynamic->IsEnabled("system.reportAnalytics", false, context);

/* getting value of a string flag named ui.textColor */

char *color1 = dynamic->GetValue("ui.textColor", "red", {"red", "blue", "green"});

char *color2 = dynamic->GetValue("ui.textColor", "green", {"red", "blue", "green"});

char *color3 = dynamic->GetValue("ui.textColor", "blue", {"red", "blue", "green"}, context);

/* getting int value of a int flag */

int n1 = dynamic->GetInt("ui.textSize", 12, {14, 18, 24});

int n2 = dynamic->GetInt("ui.textSize", 24, {14, 18, 24});

int n3 = dynamic->GetInt("ui.textSize", 12, {14, 18, 24}, context);

/* getting double value of a double flag */

double d1 = dynamic->GetDouble("math.specialNumbers", 3.14, {2.71, 0.577});

double d2 = dynamic->GetDouble("math.specialNumbers", 2.71, {2.71, 3.14, 0.577});

double d3 = dynamic->GetDouble("math.specialNumbers", 3.14, {2.71, 0.577}, context);

delete dynamic;
ROXDynamicAPI* dynamic = ROXCore.dynamicAPI;

/* boolean flag - is enabled */

BOOL report1 = [dynamic isEnabled:@"system.reportAnalytics" withDefault:FALSE];

bool report2 = [dynamic isEnabled:@"system.reportAnalytics" withDefault:TRUE];

bool report3 = [dynamic isEnabled:@"system.reportAnalytics" withDefault:FALSE context:context];

/* getting value of a string flag named ui.textColor */

NSString* color1 = [dynamic getValue:@"ui.textColor" withDefault:@"red" variations:@[@"red", @"blue", @"green"]];

NSString *color2 = [dynamic getValue:@"ui.textColor" withDefault:@"green" variations:@[@"red", @"blue", @"green"]];

NSString *color3 = [dynamic getValue:@"ui.textColor" withDefault:@"blue" variations:@[@"red", @"blue", @"green"] context:context];

/* getting int value of a int flag */

int n1 = [dynamic getInt:@"ui.textSize" withDefault:12 variations:@[@14, @18, @24]];

int n2 = [dynamic getInt:@"ui.textSize" withDefault:24 variations:@[@14, @18, @24]];

int n3 = [dynamic getInt:@"ui.textSize" withDefault:12 variations:@[@14, @18, @24] context:context];

/* getting double value of a double flag */

double d1 = [dynamic getDouble:@"math.specialNumbers" withDefault:3.14 variations:@[@2.71, @0.577]];

double d2 = [dynamic getDouble:@"math.specialNumbers" withDefault:2.71 variations:@[@2.71, @3.14, @0.577]];

double d3 = [dynamic getDouble:@"math.specialNumbers" withDefault:3.14 variations:@[@2.71, @0.577] context:context];
let dynamic = ROX.dynamicAPI()

/* boolean flag - is enabled */

let report1 = dynamic.isEnabled("system.reportAnalytics", withDefault:false)

let report2 = dynamic.isEnabled("system.reportAnalytics", withDefault:true)

let report3 = dynamic.isEnabled("system.reportAnalytics", withDefault:false, context:context)

/* getting value of a string flag named ui.textColor */

let color1 = dynamic.getValue("ui.textColor", withDefault:"red", variations:["red", "blue", "green"])

let color2 = dynamic.getValue("ui.textColor", withDefault:"green", variations:["red", "blue", "green"])

let color3 = dynamic.getValue("ui.textColor", withDefault:"blue", variations:["red", "blue", "green"], context:context)

/* getting int value of a int flag */

let n1 = dynamic.getInt("ui.textSize", withDefault:12, variations:[14, 18, 24])

let n2 = dynamic.getInt("ui.textSize", withDefault:24, variations:[14, 18, 24])

let n3 = dynamic.getInt("ui.textSize", withDefault:12, variations:[14, 18, 24], context:context)

/* getting double value of a double flag */

let d1 = dynamic.getDouble("math.specialNumbers", withDefault:3.14, variations:[2.71, 0.577])

let d2 = dynamic.getDouble("math.specialNumbers", withDefault:2.71, variations:[2.71, 3.14, 0.577])

let d3 = dynamic.getDouble("math.specialNumbers", withDefault:3.14, variations:[2.71, 0.577], context:context)