Creating configuration values

3 minute read
  • Configurations will be deprecated in SDK 5.0 and functionally merged into Flags.

  • You can still use Configurations with older SDKs. The system will automatically convert each Configuration to its corresponding type of Flag in the dashboard. Each Configuration (for example, a newly converted Flag in the dashboard) can be configured as normal. A feature flag, converted from a Configuration, will have a backward-compatible configuration label added automatically.

  • Types for Configurations will be preserved when converted to Flags.

  • Configurations with free-text input for values will also have this capability in their converted Flags.

  • Configurations do not report impression analytics.

Creating and using a configuration value using CloudBees Feature Management is simple. As soon as you define a configuration value in code and build and run your application, the newly defined configuration value will appear in the dashboard.

1. Creating a container class

To create your first configuration value, you should do the following:

  • Create a container class for your configuration.

  • Define a configuration value inside the container class by picking the name, default value, and type.

Here are example code snippets:

Swift
Objective-C
Android
React Native
JavaScript
Node.js
JavaScript SSR
import Foundation import ROX public class WelcomeScreenConf: RoxContainer{ public let title = RoxConfigurationString(defaultValue: "Welcome") public let useCDN = RoxConfigurationBool(defaultValue: true) public let networkTimeout = RoxConfigurationInt(defaultValue: 100) public let opacity = RoxConfigurationDouble(defaultValue: 0.7) }
#import <ROXCore/ROXCore.h> @interface WelcomeScreenConf : ROXBaseContainer @property (nonatomic) ROXConfigurationString* title; @property (nonatomic) ROXConfigurationBool* useCDN; @property (nonatomic) ROXConfigurationInt* networkTimeout; @property (nonatomic) ROXConfigurationDouble* opacity; @end #import "WelcomeScreenConf.h" @implementation WelcomeScreenConf - (instancetype)init { self = [super init]; if (self) { self.title = [[ROXConfigurationString alloc] initWithDefaultValue:@"test"]; self.useCDN = [[ROXConfigurationBool alloc] initWithDefaultValue:YES]; self.networkTimeout = [[ROXConfigurationInt alloc] initWithDefaultValue:10]; self.opacity = [[ROXConfigurationDouble alloc] initWithDefaultValue:0.7]; } return self; } @end
public class WelcomeScreenConf extends RoxContainer { public RoxConfigurationString title = new RoxConfigurationString("Welcome"); public RoxConfigurationBool useCDN = new RoxConfigurationBool(true); public RoxConfigurationInt networkTimeout = new RoxConfigurationInt(100); public RoxConfigurationDouble opacity = new RoxConfigurationDouble(0.7); }
const roxContainer = { title: new Rox.Configuration("Welcome"), useCDN: new Rox.Configuration(true), networkTimeout: new Rox.Configuration(100), opacity: new Rox.Configuration(0.7) }
const roxContainer = { title: new Rox.Configuration("Welcome"), useCDN: new Rox.Configuration(true), networkTimeout: new Rox.Configuration(100), opacity: new Rox.Configuration(0.7) }
const roxContainer = { title: new Rox.Configuration("Welcome"), useCDN: new Rox.Configuration(true), networkTimeout: new Rox.Configuration(100), opacity: new Rox.Configuration(0.7) }
import {Configuration} from 'rox-ssr'; const roxContainer = { title: new Configuration("Welcome"), useCDN: new Configuration(true), networkTimeout: new Configuration(100), opacity: new Configuration(0.7) }

Containers can have flags and configurations!

Containers can have both flags and configuration values—it’s simply a matter of taste.

2. Registering the container class

Once you have the container class defined, you need to register the instance to the CloudBees Feature Management SDK. This is done with the register SDK function.

The register function accepts an instance of the Container class.

Swift
Objective-C
Android
React Native
Javascript
Node.js
JavaScript SSR
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { ROX.register("<container_name>", container: WelcomeScreenConf()) ROX.setup(withKey: ROLLOUT_KEY) return true }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [ROX register:[[WelcomeScreenConf alloc] init]]; [ROX setupWithKey:@<ROLLOUT_KEY>]; return YES; }
WelcomeScreenConf welcomeScreenConf = new WelcomeScreenConf(); Rox.register("<container_name>", welcomeScreenConf);
Rox.register('<container_name>', roxContainer); ROX.setup('<rollout_key>');
Rox.register('<container_name>', roxContainer); ROX.setup('<rollout_key>');
Rox.register('<container_name>', roxContainer); ROX.setup('<rollout_key>');
import {Rox} from 'rox-ssr'; Rox.register('<container_name>', roxContainer); ROX.setup('<rollout_key>');

3. Using the configuration values

The last thing you need to do is use the configuration value in your code.

Here’s an example:

Swift
Objective-C
Android
React Native
Javascript
Node.js
JavaScript SSR
print("title is:\(conf.title.value)") print("useCDN is:\(conf.useCDN.value)") print("networkTimeout is:\(conf.networkTimeout.value)") print("opacity is:\(conf.opacity.value)")
WelcomeScreenConf* conf = (WelcomeScreenConf*) [ROXCore get:[WelcomeScreenConf class]]; NSLog(@"title is:%@",conf.title.value); NSLog(@"useCDN is:%@", conf.useCDN.value ? @"YES" : @"NO" ); NSLog(@"networkTimeout is:%d", conf.networkTimeout.value ); NSLog(@"opacity is:%f", conf.opacity.value);
WelcomeScreenConf conf = (WelcomeScreenConf) Rox.get(WelcomeScreenConf.class); Log.i(TAG, "title is:" + conf.title.getValue()); Log.i(TAG, "useCDN is:" + conf.useCDN.getValue()); Log.i(TAG, "networkTimeout is:" + conf.networkTimeout.getValue()); Log.i(TAG, "opacity is:" + conf.opacity.getValue());
const container = require('../path/to/my/container'); console.log(container.title.getValue());
const container = require('../path/to/my/container'); console.log(container.title.getValue());
const container = require('../path/to/my/container'); console.log(container.title.getValue({request : req})); // passing request as context
const container = require('../path/to/my/container'); console.log(container.title.getValue());