SDK
The official TypeScript / JavaScript client for ftflg.
Install
npm install ftflg
Initialize
Create one client per application. Pass static context at init time; update it later with setContext().
import { Ftflg } from 'ftflg';
const flags = new Ftflg({
apiKey: 'ff_your_api_key',
baseUrl: 'https://your-ftflg-instance.com',
context: {
app_version: '2.5.0',
country: 'DE',
},
}); | Option | Required | Description |
|---|---|---|
| apiKey | yes | Your project API key from the ftflg dashboard. |
| baseUrl | yes | Base URL of your ftflg instance. |
| context | no | Initial context key-value pairs. Can be updated at runtime. |
Evaluate a flag
Call eval(flagKey) to get the current state. Always guard
against null values.
const result = await flags.eval('dark_mode');
if (result.enabled) {
applyTheme(result.value ?? '#1a1a2e');
} // Evaluate multiple flags at once:
const [checkout, banner] = await Promise.all([
flags.eval('new_checkout'),
flags.eval('maintenance_banner'),
]);Return type
interface EvalResult {
enabled: boolean;
value: string | null;
} | Field | Description |
|---|---|
| enabled | true if all enabled rules passed (or flag has no rules and is enabled). |
| value | The string value attached to the flag, or null if disabled / rules failed. |
Raw HTTP (no SDK)
Any language can call the eval endpoint directly. Every body key except api_key is treated as context.
curl -X POST https://your-ftflg-instance.com/eval/dark_mode \
-H 'Content-Type: application/json' \
-d '{
"api_key": "ff_your_api_key",
"country": "DE",
"app_version": "2.5.0"
}'
# Response:
# { "enabled": true, "value": "#1a1a2e" }