Crate open_feature_ofrep

Source
Expand description

§OFREP Provider for OpenFeature

A Rust implementation of the OpenFeature OFREP provider, enabling dynamic feature flag evaluation in your applications.

This provider allows to connect to any feature flag management system that supports OFREP.

§Installation

Add the dependency in your Cargo.toml:

cargo add open-feature-ofrep
cargo add open-feature

Then integrate it into your application:

use std::time::Duration;
use open_feature::provider::FeatureProvider;
use open_feature::EvaluationContext;
use open_feature_ofrep::{OfrepProvider, OfrepOptions};
use reqwest::header::{HeaderMap, HeaderValue};

#[tokio::main]
async fn main() {
    let mut headers = HeaderMap::new();
    headers.insert("color", HeaderValue::from_static("yellow"));

    let provider = OfrepProvider::new(OfrepOptions {
        base_url: "http://localhost:8016".to_string(),
        headers: headers.clone(),
        connect_timeout: Duration::from_secs(4),
        ..Default::default()
    }).await.unwrap();

    let context = EvaluationContext::default()
                    .with_targeting_key("user-123")
                    .with_custom_field("color", "yellow");

    let result = provider.resolve_bool_value("isColorYellow", &context).await.unwrap();
    println!("Flag value: {}", result.value);
}

§Configuration Options

Configurations can be provided as constructor options. The following options are supported:

OptionType / Supported ValueDefault
base_urlstringhttp://localhost:8016
headersHeaderMapEmpty Map
connect_timeoutDuration10 seconds

§License

Apache 2.0 - See LICENSE for more information.

Structs§

OfrepOptions
OfrepProvider