Koople
Search…
Java

Getting Started

If still not registered, sign up and create an account at https://koople.io.
1. Install the Koople SDK as a dependency in your application.
Maven
Gradle
<dependency>
<groupId>io.koople</groupId>
<artifactId>server-sdk-java</artifactId>
<version>0.1.2</version>
</dependency>
implementation 'io.koople:server-sdk-java:0.1.2'
Refer to the Maven Central Repository to identify the latest version.
2. Initliaze the SDK. The SDK key authorizes your application to connect to a specific project and environment. The java SDK uses the SERVER key.
KClient client = KClient.initialize("YOUR_API_KEY");
3. Get your feature flags value.
Boolean isEnabled = client.isEnabled("myAwesomeFeature");
if (isEnabled) {
// Do something when the feature is enabled.
} else {
// Do something when the feature is not enabled.
}
Identify users to allow specific targets. See KUser.
KUser user = KUser.create("aUserId");
Boolean isEnabled = client.isEnabled("myAwesomeFeature", user);
if (isEnabled) {
// Do something when the feature is enabled.
} else {
// Do something when the feature is not enabled.
}

Methods

Initialize

Use initialize to get a validated client object.
Parameter
Description
apiKey
The server ApiKey for your project environment.
required
poolingInterval
Interval in seconds with which the SDK makes requests to the server to update the evaluation object.
optional
Interval in seconds with which the SDK makes requests to the server to update the evaluation object. The minimum value is 10 seconds. If the value is less than 10 it will be ignored and automatically set to 10. The default value is 60 seconds.
KClient client = KClient.initialize("YOUR_API_KEY", 30);

IsEnabled

The isEnabled method will return a boolean indicating whether a release toggle is enabled or disabled.
Name
Type
releaseToggleKey
string
required
user
KUser
optional
//anonymous evaluation
kKlient.isEnabled("myAwesomeFeature");
KUser user = KUser.create("aUserId");
client.isEnabled("myAwesomeFeature", user);
The evaluation of an unexistent releaseToggleKey will return false as an evaluation result.

ValueOf

The valueOf method will return a value for a remote config. You can pass an optional second parameter that will be used as a fallback if there is no value.
Name
Type
remoteConfigKey
string
required
user
KUser
optional
defaultValue
string
optional
client.valueOf("theme");
// or
client.valueOf("theme", "defaultValue");
KUser user = KKer.create("aUserId");
client.valueOf("theme", user);
//or
client.valueOf("theme", user, "defaultValue");

Objects

KUser

The KUser object represents a user with the properties to be evaluated. The properties can be added in the following ways.
Name
Type
identity
string
required
attributes
List<KUserAttribute>
optional
ArrayList<KUserAttribute> mylist = new ArrayList<KUserAttribute>() {{
add(new KUserAttribute("age", 17));
add(new KUserAttribute("gender", "male"));
}};
KUser user = KUser.create("userId", attributes);
The user can be created first for adding attributes later.
KUser user = KUser.create("userId")
.with("age", 17)
.with("gender", "male");
Also, the user can be created as an anonymous user.
KUser user = KUser.anonymous();

KUserAttribute

The KUserAttribute represents a key-value object to set the name and value of a user attribute.
Name
Type
name
string
required
value
Object
required
Value object can be a string, a number or a boolean type.
new KUserAttribute("age", 17);
new KUserAttribute("gender", "male");
new KUserAttribute("vip", true);

Copy link
On this page
Getting Started
Methods
Initialize
IsEnabled
ValueOf
Objects
KUser
KUserAttribute