Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Flipt Java

Maven Central

This directory contains the Java source code for the Flipt server-side client.

Documentation

API documentation is available at https://www.flipt.io/docs/reference/overview.

Installation

Gradle

Add the dependency in your build.gradle:

dependencies {
    implementation 'io.flipt:flipt-java:1.x.x'
}

Maven

Add the dependency in your pom.xml:

<dependency>
    <groupId>io.flipt</groupId>
    <artifactId>flipt-java</artifactId>
    <version>1.x.x</version>
</dependency>

Usage

In your Java code you can import this client and use it as so:

import io.flipt.api.FliptClient;
import io.flipt.api.evaluation.models.*;

public class Main {
  public static void main(String[] args) {
    FliptClient fliptClient = FliptClient.builder().build();
    Map<String, String> context = new HashMap<>();

    context.put("fizz", "buzz");

    EvaluationRequest variantEvaluationRequest =
        EvaluationRequest.builder()
            .namespaceKey("default")
            .flagKey("flag1")
            .entityId("entity")
            .context(context)
            .build();

    EvaluationResponse variantEvaluationResponse = fliptClient.evaluate(variantEvaluationRequest);

There is a more detailed example in the examples directory.

Setting HTTP Headers

You can set custom HTTP headers for the client by using the headers method in the builder.

FliptClient fliptClient = FliptClient.builder().headers(Map.of("X-Custom-Header", "Custom-Value")).build();

Flipt V2 Environment Support

Flipt V2 introduces the concept of environments. This client supports evaluation of flags in a specific environment by using the X-Flipt-Environment header.

FliptClient fliptClient = FliptClient.builder().headers(Map.of("X-Flipt-Environment", "production")).build();