Flaggr Documentation

Getting Started

Flaggr is an OpenFeature-compatible feature flag management platform. It allows you to control features in your applications using the standard OpenFeature SDK.

Installation

Install OpenFeature SDK
For Node.js/Server-side applications
npm install @openfeature/server-sdk
Install OpenFeature Web SDK
For Browser/Client-side applications
npm install @openfeature/web-sdk

Server-Side Usage

Initialize the Provider
import { OpenFeature } from "@openfeature/server-sdk";
import { FlaggrProvider } from "./lib/provider";

// Initialize Flaggr provider
const provider = new FlaggrProvider({
  apiUrl: "http://localhost:3000",
  apiKey: "your-api-key" // optional
});

await OpenFeature.setProviderAndWait(provider);

// Get a client
const client = OpenFeature.getClient();

// Evaluate a boolean flag
const isEnabled = await client.getBooleanValue(
  "new-feature",
  false,
  { targetingKey: "user-123", email: "user@example.com" }
);

if (isEnabled) {
  // Feature is enabled
  console.log("New feature is enabled!");
}

Client-Side Usage (React)

Using React Hooks
import { initializeFlaggr } from "./lib/client";
import { useBooleanFlag } from "./lib/client/react-hooks";

// Initialize in your app root (e.g., _app.tsx or layout.tsx)
await initializeFlaggr({
  apiUrl: "http://localhost:3000",
});

// Use in your components
function MyComponent() {
  const isNewFeatureEnabled = useBooleanFlag(
    "new-feature",
    false,
    { targetingKey: "user-123" }
  );

  return (
    <div>
      {isNewFeatureEnabled && (
        <div>New Feature Content!</div>
      )}
    </div>
  );
}

API Reference

GET /api/flags
List all feature flags
// Response
{
  "flags": [
    {
      "key": "new-feature",
      "name": "New Feature",
      "description": "Enable the new feature",
      "type": "boolean",
      "enabled": true,
      "defaultValue": false,
      "createdAt": "2025-01-01T00:00:00.000Z",
      "updatedAt": "2025-01-01T00:00:00.000Z"
    }
  ],
  "total": 1
}
POST /api/flags
Create a new feature flag
// Request
{
  "key": "new-feature",
  "name": "New Feature",
  "description": "Enable the new feature",
  "type": "boolean",
  "enabled": false,
  "defaultValue": false
}
POST /api/flags/evaluate
Evaluate a feature flag
// Request
{
  "flagKey": "new-feature",
  "context": {
    "targetingKey": "user-123",
    "email": "user@example.com"
  },
  "defaultValue": false
}

// Response
{
  "flagKey": "new-feature",
  "value": true,
  "reason": "DEFAULT"
}
POST /api/flags/[key]/toggle
Toggle a flag enabled/disabled
PATCH /api/flags/[key]
Update a feature flag
DELETE /api/flags/[key]
Delete a feature flag

Flag Types

Boolean
Simple on/off flags
true | false
String
Text-based configurations
"production" | "staging"
Number
Numeric values and limits
100 | 5000
Object
Complex structured data
{ "theme": "dark" }

Next Steps