Flipswitch

OpenFeature / OFREP

Using standard OpenFeature OFREP providers with Flipswitch

OpenFeature / OFREP

Flipswitch is fully compliant with the OpenFeature Remote Evaluation Protocol (OFREP). You can use any standard OFREP provider without installing the official Flipswitch SDKs.

Standard OFREP providers don't include real-time SSE support. For live flag updates, use the official SDKs.

When to Use Standard OFREP

  • You only need polling-based flag evaluation
  • Your language doesn't have an official Flipswitch SDK
  • You want to minimize dependencies
  • You're building a proof-of-concept

JavaScript (Web)

import { OFREPWebProvider } from '@openfeature/ofrep-web-provider';
import { OpenFeature } from '@openfeature/web-sdk';
 
const provider = new OFREPWebProvider({
  baseUrl: 'https://api.flipswitch.dev',
  headers: {
    'X-API-Key': 'YOUR_API_KEY'
  },
  // Optional: polling interval in milliseconds
  pollInterval: 30000,
});
 
await OpenFeature.setProviderAndWait(provider);
const client = OpenFeature.getClient();
 
const darkMode = await client.getBooleanValue('dark-mode', false);

JavaScript (Server)

import { OFREPProvider } from '@openfeature/ofrep-provider';
import { OpenFeature } from '@openfeature/server-sdk';
 
const provider = new OFREPProvider({
  baseUrl: 'https://api.flipswitch.dev',
  headers: {
    'X-API-Key': 'YOUR_API_KEY'
  },
});
 
await OpenFeature.setProviderAndWait(provider);
const client = OpenFeature.getClient();
 
const showFeature = await client.getBooleanValue('new-feature', false, {
  targetingKey: 'user-123',
  email: 'user@example.com'
});

Go

import (
    "github.com/open-feature/go-sdk-contrib/providers/ofrep"
    "github.com/open-feature/go-sdk/openfeature"
)
 
provider := ofrep.NewProvider(
    "https://api.flipswitch.dev",
    ofrep.WithApiKeyAuth("YOUR_API_KEY"),
)
 
openfeature.SetProvider(provider)
client := openfeature.NewClient("my-app")
 
darkMode, _ := client.BooleanValue(ctx, "dark-mode", false, openfeature.EvaluationContext{
    TargetingKey: "user-123",
})

Python

from openfeature import api
from openfeature.contrib.provider.ofrep import OFREPProvider
 
provider = OFREPProvider(
    base_url="https://api.flipswitch.dev",
    headers={"X-API-Key": "YOUR_API_KEY"},
)
 
api.set_provider(provider)
client = api.get_client()
 
dark_mode = client.get_boolean_value(
    "dark-mode",
    False,
    evaluation_context={"targetingKey": "user-123"},
)

.NET

using OpenFeature;
using OpenFeature.Contrib.Providers.Ofrep;
 
var provider = new OFREPProvider(new OFREPProviderOptions
{
    BaseUrl = "https://api.flipswitch.dev",
    Headers = new Dictionary<string, string>
    {
        ["X-API-Key"] = "YOUR_API_KEY"
    }
});
 
await Api.Instance.SetProviderAsync(provider);
var client = Api.Instance.GetClient();
 
var darkMode = await client.GetBooleanValueAsync("dark-mode", false);

OFREP Endpoints

Flipswitch exposes the following OFREP-compliant endpoints:

MethodEndpointDescription
POST/ofrep/v1/evaluate/flags/{flagKey}Evaluate a single flag
POST/ofrep/v1/evaluate/flagsBulk evaluate all flags

Single Flag Evaluation

curl -X POST https://api.flipswitch.dev/ofrep/v1/evaluate/flags/dark-mode \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "context": {
      "targetingKey": "user-123",
      "email": "user@example.com"
    }
  }'

Response:

{
  "key": "dark-mode",
  "value": true,
  "variant": "enabled",
  "reason": "TARGETING_MATCH"
}

Bulk Evaluation

curl -X POST https://api.flipswitch.dev/ofrep/v1/evaluate/flags \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "context": {
      "targetingKey": "user-123"
    }
  }'

Response:

{
  "flags": [
    {
      "key": "dark-mode",
      "value": true,
      "variant": "enabled",
      "reason": "TARGETING_MATCH"
    },
    {
      "key": "max-items",
      "value": 50,
      "variant": "high",
      "reason": "DEFAULT"
    }
  ]
}

ETag Support

Bulk evaluation supports ETags for efficient caching:

# First request
curl -X POST https://api.flipswitch.dev/ofrep/v1/evaluate/flags \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"context": {"targetingKey": "user-123"}}'
# Returns: ETag: "abc123"
 
# Subsequent requests
curl -X POST https://api.flipswitch.dev/ofrep/v1/evaluate/flags \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "If-None-Match: \"abc123\"" \
  -H "Content-Type: application/json" \
  -d '{"context": {"targetingKey": "user-123"}}'
# Returns: 304 Not Modified (if unchanged)

Supported Languages

See the OpenFeature ecosystem for all available OFREP providers:

  • JavaScript/TypeScript (web and server)
  • Go
  • Java
  • .NET
  • Python
  • PHP
  • Ruby
  • Rust
  • Swift
  • Kotlin

On this page