Skip to content

Latest commit

 

History

History
119 lines (95 loc) · 4.65 KB

README.md

File metadata and controls

119 lines (95 loc) · 4.65 KB

OpenFeature SDK for Java

Maven Central javadoc Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Specification Known Vulnerabilities on-merge codecov CII Best Practices

This is the Java implementation of OpenFeature, a vendor-agnostic abstraction library for evaluating feature flags.

We support multiple data types for flags (numbers, strings, booleans, objects) as well as hooks, which can alter the lifecycle of a flag evaluation.

This library is intended to be used in server-side contexts and has not been evaluated for use in mobile devices.

Usage

While Boolean provides the simplest introduction, we offer a variety of flag types.

import dev.openfeature.javasdk.Structure;

class MyClass {
    public UI booleanExample() {
        // Should we render the redesign? Or the default webpage? 
        if (client.getBooleanValue("redesign_enabled", false)) {
            return render_redesign();
        }
        return render_normal();
    }

    public Template stringExample() {
        // Get the template to load for the custom new homepage
        String template = client.getStringValue("homepage_template", "default-homepage.html");
        return render_template(template);
    }

    public List<HomepageModule> numberExample() {
        // How many modules should we be fetching?
        Integer count = client.getIntegerValue("module-fetch-count", 4);
        return fetch_modules(count);
    }

    public HomepageModule structureExample() {
        Structure obj = client.getObjectValue("hero-module", previouslyDefinedDefaultStructure);
        return HomepageModule.builder()
                .title(obj.getValue("title"))
                .body(obj.getValue("description"))
                .build();
    }
}

Requirements

  • Java 8+

Installation

Add it to your build

Maven

<dependency>
    <groupId>dev.openfeature</groupId>
    <artifactId>javasdk</artifactId>
    <version>0.1.0</version>
</dependency>

If you would like snapshot builds, this is the relevant repository information:

<repositories>
    <repository>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <id>sonartype</id>
        <name>Sonartype Repository</name>
        <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
    </repository>
</repositories>

Gradle

dependencies {
    implementation 'dev.openfeature:javasdk:0.1.0'
}

Configure it

To configure it, you'll need to add a provider to the global singleton OpenFeatureAPI. From there, you can generate a Client which is usable by your code. While you'll likely want a provider for your specific backend, we've provided a NoOpProvider, which simply returns the default passed in.

class MyApp {
    public void example(){
        OpenFeatureAPI api = OpenFeatureAPI.getInstance();
        api.setProvider(new NoOpProvider());
        Client client = api.getClient();
        // Now use your `client` instance to evaluate some feature flags!
    }
}

Contacting us

We hold regular meetings which you can see here.

We are also present on the #openfeature channel in the CNCF slack.

Contributors

Thanks so much to our contributors.

Pictures of the folks who have contributed to the project

Made with contrib.rocks.