Integrate feature flags into API design for gradual rollouts, A/B testing, and kill switches.
You are a platform engineer specializing in feature management and progressive delivery.
## CONTEXT
I need to implement feature flags in my API.
**Requirements:**
- Flag Types: {{FLAG_TYPES}}
- Targeting Rules: {{TARGETING}}
- Integration: {{INTEGRATION}}
- Monitoring: {{MONITORING}}
## TASK
Design feature flag integration:
### 1. FLAG DEFINITION
```json
{
"key": "new_checkout_flow",
"type": "boolean",
"defaultValue": false,
"targeting": {
"rules": [
{
"conditions": [{ "attribute": "plan", "operator": "eq", "value": "premium" }],
"value": true
}
],
"percentageRollout": 20
}
}
```
### 2. API INTEGRATION
```typescript
async function handler(req, res) {
const flags = await getFlags(req.user);
if (flags.isEnabled('new_checkout_flow')) {
return newCheckoutFlow(req, res);
}
return legacyCheckoutFlow(req, res);
}
```
### 3. CLIENT EXPOSURE
```json
GET /api/features
{
"features": {
"new_checkout_flow": true,
"dark_mode": false,
"beta_features": ["feature_a", "feature_b"]
}
}
```
### 4. TARGETING STRATEGIES
- User attributes
- Percentage rollout
- Geographic targeting
- Time-based activation
### 5. A/B TESTING
- Variant assignment
- Metrics tracking
- Statistical significance
### 6. KILL SWITCHES
Emergency feature disable mechanism.Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[{FLAG_TYPES][{TARGETING][{INTEGRATION][{MONITORING]{
"key": "new_checkout_flow",
"type": "boolean",
"defaultValue": false,
"targeting": {
"rules": [
{
"conditions": [{ "attribute": "plan", "operator": "eq", "value": "premium" }{
const flags = await getFlags(req.user);
if (flags.isEnabled('new_checkout_flow')) {
return newCheckoutFlow(req, res);
}{
"features": {
"new_checkout_flow": true,
"dark_mode": false,
"beta_features": ["feature_a", "feature_b"]
}