|
1 |
| -# Unofficial ConfigCat OpenFeature Provider for Java |
| 1 | +# ConfigCat OpenFeature Provider for Java |
2 | 2 |
|
3 |
| -[ConfigCat](https://configcat.com/) OpenFeature Provider can provide usage for ConfigCat via OpenFeature Java SDK. |
| 3 | +[ConfigCat](https://configcat.com/) OpenFeature Provider can provide usage for ConfigCat via the OpenFeature Java SDK. |
4 | 4 |
|
5 | 5 | ## Installation
|
6 | 6 |
|
7 | 7 | <!-- x-release-please-start-version -->
|
8 | 8 |
|
9 | 9 | ```xml
|
10 |
| - |
11 | 10 | <dependency>
|
12 | 11 | <groupId>dev.openfeature.contrib.providers</groupId>
|
13 | 12 | <artifactId>configcat</artifactId>
|
|
18 | 17 | <!-- x-release-please-end-version -->
|
19 | 18 |
|
20 | 19 | ## Usage
|
21 |
| -ConfigCat OpenFeature Provider is using ConfigCat Java SDK. |
| 20 | +The ConfigCat OpenFeature Provider uses a ConfigCat Java SDK client for evaluating feature flags. |
22 | 21 |
|
23 | 22 | ### Usage Example
|
24 | 23 |
|
25 |
| -``` |
26 |
| -ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder().sdkKey(sdkKey).build(); |
27 |
| -configCatProvider = new ConfigCatProvider(configCatProviderConfig); |
| 24 | +The following example shows how to use the provider with the OpenFeature SDK. |
| 25 | + |
| 26 | +```java |
| 27 | +// Build options for the ConfigCat SDK. |
| 28 | +ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder() |
| 29 | + .sdkKey("#YOUR-SDK-KEY#") |
| 30 | + .options(options -> { |
| 31 | + options.pollingMode(PollingModes.autoPoll()); |
| 32 | + options.logLevel(LogLevel.WARNING); |
| 33 | + // ... |
| 34 | + }) |
| 35 | + .build(); |
| 36 | + |
| 37 | +ConfigCatProvider configCatProvider = new ConfigCatProvider(configCatProviderConfig); |
| 38 | + |
| 39 | +// Configure the provider. |
28 | 40 | OpenFeatureAPI.getInstance().setProviderAndWait(configCatProvider);
|
29 |
| -boolean featureEnabled = client.getBooleanValue(FLAG_NAME, false); |
30 | 41 |
|
31 |
| -MutableContext evaluationContext = new MutableContext(); |
32 |
| -evaluationContext.setTargetingKey("[email protected]"); |
33 |
| -evaluationContext.add("Email", "[email protected]"); |
34 |
| -evaluationContext.add("Country", "someCountry"); |
35 |
| -featureEnabled = client.getBooleanValue(USERS_FLAG_NAME, false, evaluationContext); |
36 |
| -``` |
| 42 | +// Create a client. |
| 43 | +Client client = OpenFeatureAPI.getInstance().getClient(); |
37 | 44 |
|
38 |
| -See [ConfigCatProviderTest.java](./src/test/java/dev/openfeature/contrib/providers/configcat/ConfigCatProviderTest.java) |
39 |
| -for more information. |
| 45 | +// Evaluate your feature flag. |
| 46 | +boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false); |
| 47 | + |
| 48 | +// With evaluation context. |
| 49 | +MutableContext context = new MutableContext(); |
| 50 | +context.setTargetingKey("#SOME-USER-ID#"); |
| 51 | +context .add( "Email", "[email protected]"); |
| 52 | +context.add("Country", "CountryID"); |
| 53 | +context.add("Rating", 4.5); |
| 54 | + |
| 55 | +boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false, context); |
| 56 | +``` |
| 57 | +For a full list of configuration options see the [ConfigCat Java SDK documentation](https://configcat.com/docs/sdk-reference/java/#creating-the-configcat-client). |
40 | 58 |
|
41 | 59 | ## Notes
|
42 |
| -Some ConfigCat custom operations are supported from the provider client via: |
| 60 | +The underlying ConfigCat Client is accessible via the provider's `getConfigCatClient()` function: |
43 | 61 |
|
44 | 62 | ```java
|
45 | 63 | configCatProvider.getConfigCatClient()...
|
46 | 64 | ```
|
47 | 65 |
|
48 |
| -## ConfigCat Provider Tests Strategies |
| 66 | +## ConfigCat Provider Test Strategy |
49 | 67 |
|
50 |
| -Unit test based on ConfigCat local features file. |
| 68 | +Unit tests are based on the SDK's [local file override](https://configcat.com/docs/sdk-reference/java/#flag-overrides) feature. |
51 | 69 | See [ConfigCatProviderTest.java](./src/test/java/dev/openfeature/contrib/providers/configcat/ConfigCatProviderTest.java)
|
52 | 70 | for more information.
|
0 commit comments