Skip to content

docs(configcat): Revise docs in README.md #990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 37 additions & 19 deletions providers/configcat/README.md
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>
Expand All @@ -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.