Dynamic API

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 Python Ruby Go .NET PHP C C++
/**
  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', context, false);


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

String s1 = Rox.dynamicAPI().value('ui.textColor', "red", new String[]{"red", "green", "blue"} );
String s2 = Rox.dynamicAPI().value('ui.textColor', "green", new String[]{"red", "green", "blue"} );
String s3 = Rox.dynamicAPI().value('ui.textColor', "red", new String[]{"red", "green", "blue"}, context );
/**
  isEnabled - 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)


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

s1 = Rox.dynamic_api().value('default.newVariant', 'A', ['A', 'B', 'C'])

s2 = Rox.dynamic_api().value('default.newVariant', 'A', ['A', 'B', 'C'], 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 vlaue 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'])
var b1 = rox.DynamicAPI().IsEnabled("default.newFlag", false, nil);
var b2 = rox.DynamicAPI().IsEnabled("default.newFlag", true, nil);
var b3 = rox.DynamicAPI().IsEnabled("default.newFlag", true, context);


var s1 = rox.DynamicAPI().Value("default.newVariant", "A", []string{"A", "B", "C"}, nil))

var s2 = rox.DynamicAPI().Value("default.newVariant", "A", []string{"A", "B", "C"}, 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 vlaue 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 String vlaue of a string 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 String vlaue of a string 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()

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

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

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


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

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

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

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

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

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

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


char *color1 = dynamic->GetValue("ui.textColor", "red", std::vector<std::string>{"red", "blue", "green"}, NULL);

char *color2 = dynamic->GetValue("ui.textColor", "green", std::vector<std::string>{"red", "blue", "green"}, NULL);

char *color3 = dynamic->GetValue("ui.textColor", "blue", std::vector<std::string>{"red", "blue", "green"}, userContext);

delete dynamic;