GithubHelp home page GithubHelp logo

isabella232 / ff-java-server-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from harness/ff-java-server-sdk

0.0 0.0 0.0 748 KB

Java Server SDK for integrating with Harness Feature Flag service.

License: Apache License 2.0

Java 87.16% Mustache 12.84%

ff-java-server-sdk's Introduction

Harness Feature Flag Java SDK

Table of Contents

Intro
Requirements
Quickstart
Further Reading

Intro

Harness Feature Flags (FF) is a feature management solution that enables users to change the software’s functionality, without deploying new code. FF uses feature flags to hide code or behaviours without having to ship new versions of the software. A feature flag is like a powerful if statement.

FeatureFlags

Requirements

JDK 8 or newer
Maven or Gradle

General Dependencies

Defined in the main project

Logging Dependencies

Logback

<dependency> 
    <groupId>ch.qos.logback</groupId> 
    <artifactId>logback-classic</artifactId> 
    <version>VERSION</version> 
</dependency>

Log4j

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>VERSION</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>VERSION</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>VERSION</version>
</dependency>

Quickstart

The Feature Flag SDK provides a client that connects to the feature flag service, and fetches the value of feature flags. The following section provides an example of how to install the SDK and initialize it from an application.

This quickstart assumes you have followed the instructions to setup a Feature Flag project and have created a flag called harnessappdemodarkmode and created a server API Key.

Install the FF SDK Dependency

The first step is to install the FF SDK as a dependency in your application using your application's dependency manager. You can use Maven, Gradle, SBT, etc. for your application.

Refer to the Harness Feature Flag Java Server SDK to identify the latest version for your build automation tool.

This section lists dependencies for Maven and Gradle and uses the 1.1.5 version as an example:

Maven

Add the following Maven dependency in your project's pom.xml file:

<dependency>
    <groupId>io.harness</groupId>
    <artifactId>ff-java-server-sdk</artifactId>
    <version>1.1.5</version>
</dependency>

Gradle

implementation group: 'io.harness', name: 'ff-java-server-sdk', version: '1.1.5'

A Simple Example

After installing the SDK, enter the SDK keys that you created for your environment. The SDK keys authorize your application to connect to the FF client. All features of the Java SDK are provided by the base class called CfClient.

public class SimpleExample {
    public static void main(String[] args) {
        try {
            /**
             * Put the API Key here from your environment
             * Initialize the CfClient
             */
            String apiKey = System.getProperty("FF_API_KEY", "<default api key>");
            String flagName = System.getProperty("FF_FLAG_NAME", "<default flag name>");
            
            CfClient cfClient = new CfClient(apiKey, Config.builder().build());
            cfClient.waitForInitialization();
    
            while(true) {
                /**
                 * Sleep for sometime before printing the value of the flag
                 */
                Thread.sleep(2000);
                /**
                 * This is a sample boolean flag. You can replace the flag value with
                 * the identifier of your feature flag
                 */
                boolean result = cfClient.boolVariation(flagName, target, <default value>);
                log.info("Boolean variation is " + result);
            }
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Additional Reading

Further examples and config options are in the further reading section:

Further Reading


Harness is a feature management platform that helps teams to build better software and to test features quicker.


ff-java-server-sdk's People

Contributors

bmjen avatar davejohnston avatar enver-bisevac avatar hannah-tang avatar milos85vasic avatar mosheeshel avatar puneetsar avatar rushabh-harness avatar subiradhikari avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.