The flipt-client-java
directory contains the Java source code for the Flipt client-side evaluation client.
Add the dependency in your build.gradle
:
dependencies {
implementation 'io.flipt:flipt-client-java:0.x.x'
}
Add the dependency in your pom.xml
:
<dependency>
<groupId>io.flipt</groupId>
<artifactId>flipt-client-java</artifactId>
<version>0.x.x</version>
</dependency>
In your Java code you can import this client and use it as so:
package org.example;
import java.util.HashMap;
import java.util.Map;
import io.flipt.client.FliptEvaluationClient;
import io.flipt.client.models.*;
public class Main {
public static void main(String[] args) {
try {
FliptEvaluationClient fliptClient = FliptEvaluationClient.builder()
.url("http://localhost:8080")
.authentication(new ClientTokenAuthentication("secret"))
.build();
Map<String, String> context = new HashMap<>();
context.put("fizz", "buzz");
Result<VariantEvaluationResponse> result =
fliptClient.evaluateVariant("flag1", "entity", context);
} catch (Exception e) {
e.printStackTrace();
} finally {
// Important: always close the client to release resources
if (fliptClient != null) {
fliptClient.close();
}
}
}
}