-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(configcat): Revise docs in README.md (#990)
Signed-off-by: Peter Csajtai <[email protected]>
- Loading branch information
Showing
1 changed file
with
37 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
# Unofficial ConfigCat OpenFeature Provider for Java | ||
# ConfigCat OpenFeature Provider for Java | ||
|
||
[ConfigCat](https://configcat.com/) OpenFeature Provider can provide usage for ConfigCat via OpenFeature Java SDK. | ||
[ConfigCat](https://configcat.com/) OpenFeature Provider can provide usage for ConfigCat via the OpenFeature Java SDK. | ||
|
||
## Installation | ||
|
||
<!-- x-release-please-start-version --> | ||
|
||
```xml | ||
|
||
<dependency> | ||
<groupId>dev.openfeature.contrib.providers</groupId> | ||
<artifactId>configcat</artifactId> | ||
|
@@ -18,35 +17,54 @@ | |
<!-- x-release-please-end-version --> | ||
|
||
## Usage | ||
ConfigCat OpenFeature Provider is using ConfigCat Java SDK. | ||
The ConfigCat OpenFeature Provider uses a ConfigCat Java SDK client for evaluating feature flags. | ||
|
||
### Usage Example | ||
|
||
``` | ||
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder().sdkKey(sdkKey).build(); | ||
configCatProvider = new ConfigCatProvider(configCatProviderConfig); | ||
The following example shows how to use the provider with the OpenFeature SDK. | ||
|
||
```java | ||
// Build options for the ConfigCat SDK. | ||
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder() | ||
.sdkKey("#YOUR-SDK-KEY#") | ||
.options(options -> { | ||
options.pollingMode(PollingModes.autoPoll()); | ||
options.logLevel(LogLevel.WARNING); | ||
// ... | ||
}) | ||
.build(); | ||
|
||
ConfigCatProvider configCatProvider = new ConfigCatProvider(configCatProviderConfig); | ||
|
||
// Configure the provider. | ||
OpenFeatureAPI.getInstance().setProviderAndWait(configCatProvider); | ||
boolean featureEnabled = client.getBooleanValue(FLAG_NAME, false); | ||
|
||
MutableContext evaluationContext = new MutableContext(); | ||
evaluationContext.setTargetingKey("[email protected]"); | ||
evaluationContext.add("Email", "[email protected]"); | ||
evaluationContext.add("Country", "someCountry"); | ||
featureEnabled = client.getBooleanValue(USERS_FLAG_NAME, false, evaluationContext); | ||
``` | ||
// Create a client. | ||
Client client = OpenFeatureAPI.getInstance().getClient(); | ||
|
||
See [ConfigCatProviderTest.java](./src/test/java/dev/openfeature/contrib/providers/configcat/ConfigCatProviderTest.java) | ||
for more information. | ||
// Evaluate your feature flag. | ||
boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false); | ||
|
||
// With evaluation context. | ||
MutableContext context = new MutableContext(); | ||
context.setTargetingKey("#SOME-USER-ID#"); | ||
context.add("Email", "[email protected]"); | ||
context.add("Country", "CountryID"); | ||
context.add("Rating", 4.5); | ||
|
||
boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false, context); | ||
``` | ||
For a full list of configuration options see the [ConfigCat Java SDK documentation](https://configcat.com/docs/sdk-reference/java/#creating-the-configcat-client). | ||
|
||
## Notes | ||
Some ConfigCat custom operations are supported from the provider client via: | ||
The underlying ConfigCat Client is accessible via the provider's `getConfigCatClient()` function: | ||
|
||
```java | ||
configCatProvider.getConfigCatClient()... | ||
``` | ||
|
||
## ConfigCat Provider Tests Strategies | ||
## ConfigCat Provider Test Strategy | ||
|
||
Unit test based on ConfigCat local features file. | ||
Unit tests are based on the SDK's [local file override](https://configcat.com/docs/sdk-reference/java/#flag-overrides) feature. | ||
See [ConfigCatProviderTest.java](./src/test/java/dev/openfeature/contrib/providers/configcat/ConfigCatProviderTest.java) | ||
for more information. |