Java implementation of the OpenFeature SDK
Go to file
Justin Abrahms d8c82be099
Add release instructions & build caches
2022-06-24 00:04:35 -05:00
.github/workflows Add release instructions & build caches 2022-06-24 00:04:35 -05:00
release Add release instructions & build caches 2022-06-24 00:04:35 -05:00
src Working on release 2022-06-23 16:40:45 -05:00
.gitattributes Skeleton implementation of the java sdk 2022-04-20 21:12:09 -07:00
.gitignore Add support for coverage. 2022-06-23 12:38:44 -05:00
CONTRIBUTING.md Add a contributing.md 2022-06-17 21:05:12 -07:00
LICENSE Add Apache2.0 license 2022-04-29 15:21:59 -04:00
README.md Fix known vuln badge. 2022-06-15 09:06:40 -07:00
pom.xml Remove unknown param for java8 2022-06-23 21:59:15 -05:00
settings.gradle Skeleton implementation of the java sdk 2022-04-20 21:12:09 -07:00
spec_finder.py Fix spec parser to work with latest changes 2022-06-20 18:48:47 -05:00

README.md

OpenFeature SDK for Java

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

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.

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<Module> numberExample() {
        // How many modules should we be fetching?
        Integer count = client.getIntegerValue("module-fetch-count", 4);
        return fetch_modules(count);
    }
    
    public Module structureExample() {
        // This deserializes into the Module structure for you.
        Module heroModule = client.getObjectValue("hero-module", myExampleModule);
        return heroModule;
    }
}

Requirements

  • Java 11+

Installation

Add it to your build

Maven:

<dependency>
    <groupId>dev.openfeature</groupId>
    <artifactId>javasdk</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

Gradle:

dependencies {
    implementation 'dev.openfeature:javasdk:0.0.1-SNAPSHOT'
}

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.

Made with contrib.rocks.