Skip to content

Commit 1ce5ea5

Browse files
rolodatotoddbaert
andauthored
docs(flagsmith): Improve README (#872)
Signed-off-by: Rodrigo López Dato <rodrigo@rolodato.com> Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
1 parent 53f4435 commit 1ce5ea5

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

providers/flagsmith/README.md

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Flagsmith OpenFeature Java Provider
22
![Experimental](https://img.shields.io/badge/experimental-breaking%20changes%20allowed-yellow)
33
[![Download](https://img.shields.io/maven-central/v/com.flagsmith/flagsmith-java-client)](https://mvnrepository.com/artifact/com.flagsmith/flagsmith-java-client)
4+
45
Flagsmith provides an all-in-one platform for developing, implementing, and managing your feature flags.
56

67
## Installation
78

89
<!-- x-release-please-start-version -->
910

1011
```xml
11-
1212
<dependency>
1313
<groupId>dev.openfeature.contrib.providers</groupId>
1414
<artifactId>flagsmith</artifactId>
@@ -20,24 +20,46 @@ Flagsmith provides an all-in-one platform for developing, implementing, and mana
2020

2121
## Usage
2222

23-
The `FlagsmithProvider` communicates with Flagsmith using the Flagsmith java sdk. Information on the sdk can be found in
24-
the Flagsmith documentaiton here https://docs.flagsmith.com/clients/server-side. The following code snippet shows how to
25-
initialize the `FlagsmithProvider`:
23+
The `FlagsmithProvider` communicates with Flagsmith using the [Flagsmith Java SDK](https://docs.flagsmith.com/clients/server-side?language=java).
24+
This example shows how to initialize and use the Flagsmith OpenFeature provider:
2625

2726
```java
28-
FlagsmithProviderOptions options = FlagsmithProviderOptions.builder()
29-
.apiKey("API_KEY")
30-
.build();
31-
32-
FlagsmithProvider provider = new FlagsmithProvider();
33-
OpenFeatureAPI.getInstance().setProvider(provider);
27+
import dev.openfeature.contrib.providers.flagsmith.FlagsmithProvider;
28+
import dev.openfeature.contrib.providers.flagsmith.FlagsmithProviderOptions;
29+
import dev.openfeature.sdk.Client;
30+
import dev.openfeature.sdk.MutableContext;
31+
import dev.openfeature.sdk.OpenFeatureAPI;
32+
33+
public class FlagsmithExample {
34+
public static void main(String[] args) {
35+
FlagsmithProviderOptions options = FlagsmithProviderOptions.builder()
36+
.apiKey("API_KEY")
37+
.build();
38+
39+
FlagsmithProvider provider = new FlagsmithProvider(options);
40+
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
41+
api.setProvider(provider);
42+
43+
// Optional: set a targeting key and traits to use segment and/or identity overrides
44+
MutableContext evaluationContext = new MutableContext();
45+
evaluationContext.setTargetingKey("my-identity-id");
46+
47+
Client client = api.getClient();
48+
boolean flag = client.getBooleanValue("my-boolean-flag", false, evaluationContext);
49+
System.out.println(flag);
50+
}
51+
}
3452
```
3553

3654
Options can be defined using the FlagsmithProviderOptions builder. Below are all the options:
3755

3856
| Option name | Type | Default | Description
3957
| ----------- | ------- | --------- | ---------
4058
| apiKey | String | | Your API Token. Note that this is either the `Environment API` key or the `Server Side SDK Token`
59+
| baseUri | String | https://edge.api.flagsmith.com/api/v1/ | Override the default Flagsmith API URL if you are self-hosting.
60+
| localEvaluation | boolean | false | Controls which mode to run in; [local or remote evaluation](https://docs.flagsmith.com/clients/overview#server-side-sdks).
61+
| environmentRefreshIntervalSeconds | int | 60 | Set environment refresh rate when using local evaluation mode
62+
| enableAnalytics | boolean | false | Controls whether [Flag Analytics](https://docs.flagsmith.com/advanced-use/flag-analytics) data is sent to the Flagsmith API
4163
| headers | HashMap<String, String> | | Add custom headers which will be sent with each network request to the Flagsmith API.
4264
| envFlagsCacheKey | String | | Enable in-memory caching for the Flagsmith API.
4365
| expireCacheAfterWriteTimeUnit | TimeUnit | TimeUnit.MINUTES | The time unit used for cache expiry after write.
@@ -46,35 +68,11 @@ Options can be defined using the FlagsmithProviderOptions builder. Below are all
4668
| expireCacheAfterAccess | int | -1 | The integer time for cache expiry after reading.
4769
| maxCacheSize | int | -1 | The maximum size of the cache in MB.
4870
| recordCacheStats | boolean | false | Whether cache statistics should be recorded.
49-
| baseUri | String | https://edge.api.flagsmith.com/api/v1/ | Override the default Flagsmith API URL if you are self-hosting.
5071
| connectTimeout | int | 2000 | The network timeout in milliseconds.
5172
| writeTimeout | int | 5000 | The network timeout in milliseconds when writing.
5273
| readTimeout | int | 5000 | The network timeout in milliseconds when reading.
5374
| sslSocketFactory | SSLSocketFactory | | Override the sslSocketFactory.
5475
| trustManager | X509TrustManager | | X509TrustManager used when overriding the sslSocketFactory.
5576
| httpInterceptor | Interceptor | | Add a custom HTTP interceptor in the form of an okhttp3.Interceptor object.
5677
| retries | int | 3 | Add a custom com.flagsmith.config.Retry object to configure the backoff / retry configuration.
57-
| localEvaluation | boolean | false | Controls which mode to run in; local or remote evaluation.
58-
| environmentRefreshIntervalSeconds | int | 60 | Set environment refresh rate with polling manager.
59-
| enableAnalytics | boolean | false | Controls whether Flag Analytics data is sent to the Flagsmith API
60-
| usingBooleanConfigValue | boolean | false | Determines whether to resolve a feature value as a boolean or use the isFeatureEnabled as the flag itself. These values will be false and true respectively.
61-
62-
### Identity flags
63-
64-
In order to use specific identity flags, a targeting key must be provided in the EvaluationContext provided to the flag
65-
evaluation method. An example of this can be seen below:
66-
67-
```java
68-
FlagsmithProviderOptions options = FlagsmithProviderOptions.builder()
69-
.apiKey("API_KEY")
70-
.build();
71-
72-
FlagsmithProvider provider = new FlagsmithProvider();
73-
OpenFeatureAPI.getInstance().setProvider(provider);
74-
75-
EvaluationContext evaluationContext = new MutableContext();
76-
evaluationContext.setTargetingKey("my-identity");
77-
78-
Client client = api.getClient();
79-
boolean flag = client.getBooleanValue("key", false);
80-
```
78+
| usingBooleanConfigValue | boolean | false | Determines whether to resolve a feature value as a boolean or use the isFeatureEnabled as the flag itself. These values will be false and true respectively.

0 commit comments

Comments
 (0)