Usage Examples
Flagship supports multiple programming languages and frameworks through OpenFeature. Here are some examples of how to implement feature flags.
typescript
const client = OpenFeature.getClient();
// The AI detects this new key 'new-checkout-flow' in your PR
// Flagship automatically creates the flag if it doesn't exist
const isNewCheckoutEnabled = await client.getBooleanValue('new-checkout-flow', false, {
targetingKey: user.id, // Critical for percentage rollouts!
// Add other context attributes for targeting rules
email: user.email,
plan: user.plan
});
if (isNewCheckoutEnabled) {
return renderNewCheckout();
} else {
return renderLegacyCheckout();
}python
client = api.get_client()
# The AI detects this new key 'new-checkout-flow' in your PR
# Ensure you provide a targeting_key for deterministic rollouts
is_new_checkout_enabled = client.get_boolean_value(
"new-checkout-flow",
False,
EvaluationContext(
targeting_key=user.id,
attributes={
"email": user.email,
"plan": user.plan
}
)
)
if is_new_checkout_enabled:
return render_new_checkout()
else:
return render_legacy_checkout()go
client := openfeature.NewClient("app")
// The AI detects this new key 'new-checkout-flow' in your PR
evalCtx := openfeature.NewEvaluationContext(
user.ID, // This is mapped to targetingKey
map[string]interface{}{
"email": user.Email,
"plan": user.Plan,
},
)
isNewCheckoutEnabled, _ := client.BooleanValue(
context.Background(),
"new-checkout-flow",
false,
evalCtx,
)
if isNewCheckoutEnabled {
return renderNewCheckout()
} else {
return renderLegacyCheckout()
}java
Client client = OpenFeatureAPI.getInstance().getClient();
// The AI detects this new key 'new-checkout-flow' in your PR
// The constructor argument is the targetingKey
MutableContext context = new MutableContext(user.getId());
context.add("email", user.getEmail());
context.add("plan", user.getPlan());
Boolean isNewCheckoutEnabled = client.getBooleanValue("new-checkout-flow", false, context);
if (isNewCheckoutEnabled) {
return renderNewCheckout();
} else {
return renderLegacyCheckout();
}