Skip to content

Commit a7b1416

Browse files
committed
Add OpenFeature providers to SDK reference
1 parent 4a381b4 commit a7b1416

File tree

25 files changed

+1643
-19
lines changed

25 files changed

+1643
-19
lines changed

website/docs/sdk-reference/go.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ If you want to use multiple SDK Keys in the same application, create only one _C
114114

115115
## Anatomy of `Get[TYPE]Value()`
116116

117-
Basically all of the value evaluator methods share the same signature, they only differ in their served value type. `GetBoolValue()` is for evaluating feature flags, `GetIntValue()` and `GetFloatValue()` are for numeric and `GetStringValue()` is for textual settings.
117+
All feature flag evaluator methods share the same signature, they only differ in their served value type. `GetBoolValue()` is for evaluating feature flags, `GetIntValue()` and `GetFloatValue()` are for numeric and `GetStringValue()` is for textual settings.
118118

119119
| Parameters | Description |
120120
| -------------- | -------------------------------------------------------------------------------------------------- |

website/docs/sdk-reference/java.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ User user = User.newBuilder().build("[email protected]");
265265

266266
```java
267267
java.util.Map<String,Object> customAttributes = new java.util.HashMap<String,Object>();
268-
customAttributes.put("SubscriptionType", "Pro");
269-
customAttributes.put("UserRole", "Admin");
268+
customAttributes.put("SubscriptionType", "Pro");
269+
customAttributes.put("UserRole", "Admin");
270270

271271
User user = User.newBuilder()
272272
@@ -279,9 +279,9 @@ The `Custom` dictionary also allows attribute values other than `String` values:
279279

280280
```java
281281
java.util.Map<String,Object> customAttributes = new java.util.HashMap<String,Object>();
282-
customAttributes.put("Rating", 4.5);
283-
customAttributes.put("RegisteredAt", new Date("2023-11-22 12:34:56 +00:00"));
284-
customAttributes.put("Roles", new String[]{"Role1", "Role2"});
282+
customAttributes.put("Rating", 4.5);
283+
customAttributes.put("RegisteredAt", new Date("2023-11-22 12:34:56 +00:00"));
284+
customAttributes.put("Roles", new String[]{"Role1", "Role2"});
285285

286286
User user = User.newBuilder()
287287
@@ -395,7 +395,7 @@ Use the `cacheRefreshIntervalInSeconds` option parameter of the `PollingModes.la
395395

396396
```java
397397
ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#", options -> {
398-
options.pollingMode(PollingModes.lazyLoad(60 /* the cache will expire in 120 seconds */));
398+
options.pollingMode(PollingModes.lazyLoad(60 /* the cache will expire in 120 seconds */));
399399
});
400400
```
401401

@@ -413,7 +413,7 @@ Manual polling gives you full control over when the `config JSON` (with the sett
413413

414414
```java
415415
ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#", options ->{
416-
options.pollingMode(PollingModes.manualPoll());
416+
options.pollingMode(PollingModes.manualPoll());
417417
});
418418

419419
client.forceRefresh();
@@ -699,7 +699,7 @@ map.put("doubleSetting", 3.14);
699699
map.put("stringSetting", "test");
700700

701701
ConfigCatClient client = ConfigCatClient.get("localhost", options -> {
702-
options.flagOverrides(OverrideDataSourceBuilder.map(map), OverrideBehaviour.LOCAL_ONLY)
702+
options.flagOverrides(OverrideDataSourceBuilder.map(map), OverrideBehaviour.LOCAL_ONLY)
703703
});
704704
```
705705

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
id: dotnet
3+
title: OpenFeature Provider for .NET
4+
description: ConfigCat OpenFeature Provider for .NET. This is a step-by-step guide on how to use ConfigCat with the OpenFeature .NET SDK.
5+
---
6+
7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
10+
<a href="https://github.com/open-feature/dotnet-sdk-contrib/tree/main/src/OpenFeature.Contrib.Providers.ConfigCat" target="_blank">ConfigCat OpenFeature Provider for .NET on GitHub</a>
11+
12+
## Getting started
13+
14+
### 1. Install the provider
15+
16+
<Tabs groupId="dotnet-install">
17+
<TabItem value="Powershell / NuGet Package Manager Console" label="Powershell / NuGet Package Manager Console">
18+
19+
```powershell
20+
Install-Package OpenFeature.Contrib.Providers.ConfigCat
21+
```
22+
23+
</TabItem>
24+
<TabItem value=".NET CLI" label=".NET CLI">
25+
26+
```bash
27+
dotnet add package OpenFeature.Contrib.Providers.ConfigCat
28+
```
29+
30+
</TabItem>
31+
<TabItem value="Package Reference" label="Package Reference">
32+
33+
```xml
34+
<PackageReference Include="OpenFeature.Contrib.Providers.ConfigCat" />
35+
```
36+
37+
</TabItem>
38+
</Tabs>
39+
### 2. Initialize the provider
40+
41+
The `ConfigCatProvider` constructor takes the SDK key and an optional `ConfigCatClientOptions` argument containing the additional configuration options for the [ConfigCat .NET SDK](../../dotnet/#creating-the-configcat-client):
42+
43+
```cs
44+
using OpenFeature.Contrib.Providers.ConfigCat;
45+
46+
// Build options for the ConfigCat SDK.
47+
var options = new ConfigCatClientOptions
48+
{
49+
PollingMode = PollingModes.AutoPoll(pollInterval: TimeSpan.FromSeconds(60));
50+
Logger = new ConsoleLogger(LogLevel.Warning);
51+
// ...
52+
};
53+
54+
// Configure the provider.
55+
OpenFeature.Api.Instance.SetProvider(new ConfigCatProvider("#YOUR-SDK-KEY#", options));
56+
57+
// Create a client.
58+
var client = OpenFeature.Api.Instance.GetClient();
59+
```
60+
61+
For more information about all the configuration options, see the [.NET SDK documentation](../../dotnet/#creating-the-configcat-client).
62+
63+
### 3. Evaluate your feature flag
64+
65+
```cs
66+
var isAwesomeFeatureEnabled = await client.GetBooleanValueAsync("isAwesomeFeatureEnabled", false);
67+
if(isAwesomeFeatureEnabled)
68+
{
69+
doTheNewThing();
70+
}
71+
else
72+
{
73+
doTheOldThing();
74+
}
75+
```
76+
77+
## Evaluation Context
78+
79+
An <a href="https://openfeature.dev/docs/reference/concepts/evaluation-context" target="_blank">evaluation context</a> in the OpenFeature specification is a container for arbitrary contextual data that can be used as a basis for feature flag evaluation.
80+
The ConfigCat provider translates these evaluation contexts to ConfigCat [User Objects](../../dotnet/#user-object).
81+
82+
The following table shows how the different context attributes are mapped to User Object attributes.
83+
84+
| Evaluation context | User Object | Required |
85+
| ------------------ | ------------ | -------- |
86+
| `Id`/`Identifier` | `Identifier` | &#9745; |
87+
| `Email` | `Email` | |
88+
| `Country` | `Country` | |
89+
| Any other | `Custom` | |
90+
91+
To evaluate feature flags for a context, use the <a href="https://openfeature.dev/docs/reference/concepts/evaluation-api/" target="_blank">OpenFeature Evaluation API</a>:
92+
93+
```cs
94+
var context = new EvaluationContext()
95+
.Set("Id", "#SOME-USER-ID#")
96+
.Set("Email", "[email protected]")
97+
.Set("Country", "CountryID")
98+
.Set("Rating", 4.5)
99+
.Set("RegisteredAt", DateTime.Parse("2023-11-22 12:34:56 +00:00", CultureInfo.InvariantCulture))
100+
.Build();
101+
102+
var isAwesomeFeatureEnabled = await client.GetBooleanValueAsync("isAwesomeFeatureEnabled", false, context);
103+
```
104+
105+
## Look under the hood
106+
107+
- <a href="https://github.com/open-feature/dotnet-sdk-contrib/tree/main/src/OpenFeature.Contrib.Providers.ConfigCat" target="_blank">ConfigCat OpenFeature Provider's repository on GitHub</a>
108+
- <a href="https://www.nuget.org/packages/OpenFeature.Contrib.Providers.ConfigCat" target="_blank">ConfigCat OpenFeature Provider on nuget.org</a>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
id: go
3+
title: OpenFeature Provider for Go
4+
description: ConfigCat OpenFeature Provider for Go. This is a step-by-step guide on how to use ConfigCat with the OpenFeature Go SDK.
5+
---
6+
7+
<a href="https://github.com/open-feature/go-sdk-contrib/tree/main/providers/configcat" target="_blank">ConfigCat OpenFeature Provider for Go on GitHub</a>
8+
9+
## Getting started
10+
11+
### 1. Install the provider
12+
13+
```bash
14+
go get github.com/open-feature/go-sdk-contrib/providers/configcat
15+
```
16+
17+
### 2. Initialize the provider
18+
19+
The ConfigCat Provider needs a pre-configured [ConfigCat Go SDK](../../go/#creating-the-configcat-client) client:
20+
21+
```go
22+
import (
23+
"context"
24+
25+
sdk "github.com/configcat/go-sdk/v9"
26+
configcat "github.com/open-feature/go-sdk-contrib/providers/configcat/pkg"
27+
"github.com/open-feature/go-sdk/openfeature"
28+
)
29+
30+
// Configure the ConfigCat SDK.
31+
configcatClient := sdk.NewCustomClient(sdk.Config{SDKKey: "#YOUR-SDK-KEY#",
32+
PollingMode: sdk.AutoPoll,
33+
PollInterval: time.Second * 60})
34+
35+
// Configure the provider.
36+
openfeature.SetProvider(configcat.NewProvider(configcatClient))
37+
38+
# Create a client.
39+
client := openfeature.NewClient("app")
40+
```
41+
42+
For more information about all the configuration options, see the [Go SDK documentation](../../go/#creating-the-configcat-client).
43+
44+
### 3. Evaluate your feature flag
45+
46+
```rust
47+
isAwesomeFeatureEnabled, err := client.BooleanValue(
48+
context.Background(), "isAwesomeFeatureEnabled", false, openfeature.EvaluationContext{},
49+
)
50+
51+
if err == nil && isAwesomeFeatureEnabled {
52+
doTheNewThing()
53+
} else {
54+
doTheOldThing()
55+
}
56+
```
57+
58+
## Evaluation Context
59+
60+
An <a href="https://openfeature.dev/docs/reference/concepts/evaluation-context" target="_blank">evaluation context</a> in the OpenFeature specification is a container for arbitrary contextual data that can be used as a basis for feature flag evaluation.
61+
The ConfigCat provider translates these evaluation contexts to ConfigCat [User Objects](../../go/#user-object).
62+
63+
The following table shows how the different context attributes are mapped to User Object attributes.
64+
65+
| Evaluation context | User Object | Required |
66+
| ------------------------------- | ------------ | -------- |
67+
| `openfeature.TargetingKey` | `Identifier` | &#9745; |
68+
| `configcat.EmailKey` | `Email` | |
69+
| `configcat.CountryKey` | `Country` | |
70+
| Any other | `Custom` | |
71+
72+
To evaluate feature flags for a context, use the <a href="https://openfeature.dev/docs/reference/concepts/evaluation-api/" target="_blank">OpenFeature Evaluation API</a>:
73+
74+
```go
75+
registeredAt, _ := time.Parse(time.DateTime, "2023-11-22 12:34:56")
76+
context := openfeature.NewEvaluationContext("#SOME-USER-ID#", map[string]any{
77+
configcat.EmailKey: "[email protected]",
78+
configcat.CountryKey: "CountryID",
79+
"Rating": 4.5,
80+
"RegisteredAt": registeredAt,
81+
"Roles": []string{"Role1","Role2"},
82+
})
83+
84+
isAwesomeFeatureEnabled, err := client.BooleanValue(
85+
context.Background(), "isAwesomeFeatureEnabled", false, context,
86+
)
87+
```
88+
89+
## Look under the hood
90+
91+
- <a href="https://github.com/open-feature/go-sdk-contrib/tree/main/providers/configcat" target="_blank">ConfigCat OpenFeature Provider's repository on GitHub</a>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
id: java
3+
title: OpenFeature Provider for Java
4+
description: ConfigCat OpenFeature Provider for Java. This is a step-by-step guide on how to use ConfigCat with the OpenFeature Java SDK.
5+
---
6+
7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
10+
<a href="https://github.com/open-feature/java-sdk-contrib/tree/main/providers/configcat" target="_blank">ConfigCat OpenFeature Provider for Java on GitHub</a>
11+
12+
## Getting started
13+
14+
### 1. Install the provider
15+
16+
<Tabs groupId="java-install">
17+
<TabItem value="Gradle" label="Gradle">
18+
19+
```groovy title="build.gradle"
20+
dependencies {
21+
implementation 'dev.openfeature.contrib.providers:configcat:0.0.4'
22+
}
23+
```
24+
25+
</TabItem>
26+
<TabItem value="Maven" label="Maven">
27+
28+
```xml title="pom.xml"
29+
<dependency>
30+
<groupId>dev.openfeature.contrib.providers</groupId>
31+
<artifactId>configcat</artifactId>
32+
<version>0.0.4</version>
33+
</dependency>
34+
```
35+
36+
</TabItem>
37+
</Tabs>
38+
### 2. Initialize the provider
39+
40+
The `ConfigCatProvider` constructor takes a `ConfigCatProviderConfig` argument containing the configuration options for the [ConfigCat Java SDK](../../java/#creating-the-configcat-client):
41+
42+
```java
43+
// Build options for the ConfigCat SDK.
44+
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder()
45+
.sdkKey("#YOUR-SDK-KEY#")
46+
.pollingMode(PollingModes.autoPoll())
47+
.logLevel(LogLevel.WARNING)
48+
.build();
49+
50+
// Configure the provider.
51+
OpenFeatureAPI.getInstance().setProviderAndWait(new ConfigCatProvider(configCatProviderConfig));
52+
53+
// Create a client.
54+
Client client = OpenFeatureAPI.getInstance().getClient();
55+
```
56+
57+
For more information about all the configuration options, see the [Java SDK documentation](../../java/#creating-the-configcat-client).
58+
59+
### 3. Evaluate your feature flag
60+
61+
```cs
62+
boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false);
63+
if(isAwesomeFeatureEnabled)
64+
{
65+
doTheNewThing();
66+
}
67+
else
68+
{
69+
doTheOldThing();
70+
}
71+
```
72+
73+
## Evaluation Context
74+
75+
An <a href="https://openfeature.dev/docs/reference/concepts/evaluation-context" target="_blank">evaluation context</a> in the OpenFeature specification is a container for arbitrary contextual data that can be used as a basis for feature flag evaluation.
76+
The ConfigCat provider translates these evaluation contexts to ConfigCat [User Objects](../../java/#user-object).
77+
78+
The following table shows how the different context attributes are mapped to User Object attributes.
79+
80+
| Evaluation context | User Object | Required |
81+
| ------------------ | ------------ | -------- |
82+
| `TargetingKey` | `identifier` | &#9745; |
83+
| `Email` | `email` | |
84+
| `Country` | `country` | |
85+
| Any other | `custom` | |
86+
87+
To evaluate feature flags for a context, use the <a href="https://openfeature.dev/docs/reference/concepts/evaluation-api/" target="_blank">OpenFeature Evaluation API</a>:
88+
89+
```cs
90+
MutableContext evaluationContext = new MutableContext();
91+
evaluationContext.setTargetingKey("#SOME-USER-ID#");
92+
evaluationContext.add("Email", "[email protected]");
93+
evaluationContext.add("Country", "CountryID");
94+
evaluationContext.add("Rating", 4.5);
95+
96+
boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false, context);
97+
```
98+
99+
## Look under the hood
100+
101+
- <a href="https://github.com/open-feature/java-sdk-contrib/tree/main/providers/configcat" target="_blank">ConfigCat OpenFeature Provider's repository on GitHub</a>
102+
- <a href="https://search.maven.org/artifact/dev.openfeature.contrib.providers/configcat" target="_blank">ConfigCat OpenFeature Provider on Maven Central</a>

0 commit comments

Comments
 (0)