ConfigCat Java SDK https://configcat.com
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper
media
samples
src
.DS_Store
.gitignore
.travis.yml
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

ConfigCat SDK for Java

ConfigCat SDK for Java provides easy integration between ConfigCat service and applications using Java.

ConfigCat is a feature flag, feature toggle, and configuration management service. That lets you launch new features and change your software configuration remotely without actually (re)deploying code. ConfigCat even helps you do controlled roll-outs like canary releases and blue-green deployments. https://configcat.com

Build Status Maven Central Coverage Status Javadocs License

Getting started

1. Install the package

Maven:

<dependency>
    <groupId>com.configcat</groupId>
    <artifactId>configcat-client</artifactId>
    <version>[2.0.0,)</version>
</dependency>

Gradle:

compile 'com.configcat:configcat-client:2.+'

2. Log in to ConfigCat Management Console and go to your Project to get your API Key:

API-KEY

3. Import com.configcat.* to your application

import com.configcat.*;

4. Create the ConfigCat client instance

ConfigCatClient client = new ConfigCatClient("#YOUR-API-KEY#");

5. Get your setting value:

boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "isMyAwesomeFeatureEnabled", false);
if(isMyAwesomeFeatureEnabled) {
    doTheNewThing();
} else{
    doTheOldThing();
}

Or use the async APIs:

client.getValueAsync(Boolean.class, "isMyAwesomeFeatureEnabled", false)
    .thenAccept(isMyAwesomeFeatureEnabled -> {
        if(isMyAwesomeFeatureEnabled) {
            doTheNewThing();
        } else{
            doTheOldThing();
        }
    });

Android

The minimum supported sdk version is 26 (oreo). Java 1.8 or later is required.

android {
    defaultConfig {
        //...
        minSdkVersion 26
    }
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

You also have to put this line into your manifest xml to enable the library access to the network.

<uses-permission android:name="android.permission.INTERNET" />

Getting user specific setting values with Targeting

Using this feature, you will be able to get different setting values for different users in your application by passing a User Object to the getValue() function.

Read more about Targeting here.

User object

Percentage and targeted rollouts are calculated by the user object you can optionally pass to the configuration requests. The user object must be created with a mandatory identifier parameter which should uniquely identify each user:

User user = User.newBuilder()
        .build("#USER-IDENTIFIER#"); // mandatory

boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "isMyAwesomeFeatureEnabled", user, false);
if(isMyAwesomeFeatureEnabled) {
    doTheNewThing();
} else{
    doTheOldThing();
}

Sample/Demo app

Polling Modes

The ConfigCat SDK supports 3 different polling mechanisms to acquire the setting values from ConfigCat. After latest setting values are downloaded, they are stored in the internal cache then all requests are served from there. Read more about Polling Modes and how to use them at ConfigCat Java Docs or ConfigCat Android Docs.

Support

If you need help how to use this SDK feel free to to contact the ConfigCat Staff on https://configcat.com. We're happy to help.

Contributing

Contributions are welcome.

About ConfigCat