Skip to content

Commit

Permalink
chore: update readme usage
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert committed Oct 19, 2022
1 parent 6c19e8b commit b87a9a7
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,46 @@ This library is intended to be used in server-side contexts and has not been eva

## Usage

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

```java
import dev.openfeature.sdk.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();
}
import dev.openfeature.javasdk.OpenFeatureAPI;

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);
}
// configure a provider
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProvider(new YourProviderOfChoice());

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

// get a boolean value
Boolean boolValue = client.getBooleanValue("boolFlag", false);

// get a string value
String stringValue = client.getStringValue("stringFlag", "default");

// get an integer value
Integer intValue = client.getIntegerValue("intFlag", 1);

// get a double value
Double doubleValue = client.getDoubleValue("doubleFlag", 0.9);

// get an object value
Value objectValue = client.getObjectValue("objectFlag", MyObjectInstance);

// get details of boolean evaluation
FlagEvaluationDetails<Boolean> boolDetails = client.getBooleanDetails("boolFlag", false);

// get details of string evaluation
FlagEvaluationDetails<String> stringDetails = client.getStringDetails("stringFlag", "default");

// get details of integer evaluation
FlagEvaluationDetails<Integer> intDetails = client.getIntegerDetails("intFlag", 1);

// get details of double evaluation
FlagEvaluationDetails<Doulbe> doubleDetails = client.getDoubleDetails("doubleFlag", .9);

// get details of object evaluation
FlagEvaluationDetails<Value> objectDetails = client.getObjectDetails<MyObject>("objectFlag", myObjectDefaultInstance);

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

## Requirements
Expand Down

0 comments on commit b87a9a7

Please sign in to comment.