- Introduction
- Screenshots
- Not Ready for Production
- Quickstart
- Server Setup
- Rest API
- JS/TS/Node SDK
- React SDK
- FlagLeap is a simple & flexible solution for managing realtime feature flags.
- It is meant to be deployed as a standalone service, and can be consumed via a REST API.
- SDKs for JavaScript (browser and node), TypeScript, and React (web) are included.
- FlagLeap supports rule-based, user-specific flag evaluations (with multiple rule types).
- It has 2 modes:
liveandtest. (Rules intestmode don't affectlivemode.)
| List of Flags | Flag-Specific Rules |
|---|---|
![]() |
![]() |
- FlagLeap is not yet ready for production use.
- External & internal APIs are both likely change.
- However, it is ready for POCs and non-critical internal apps.
- Please complete the Server Setup steps.
- And use any (one or more) of the following to interact with the server:
git clone https://github.com/sumukhbarve/flagleap.gitcd flagleapnpm installnpm run buildnpm start
- Visit http://localhost:3333 and complete account setup.
- Click 'Create Flag' and enter the an ID (eg.
enableFoo) for the flag.
PORT(defaults to 3333)DATABASE_URL(defaults to repo/local-sqlite.db)SECRET_KEY(defaults to not-really-a-secret--just-the-fallback)
A flag, as returned by the REST API (and SDKs) has the following shape:
interface Flag {
id: string
enabled: boolean
value: string
}A FlagMap is a mapping from flag IDs to corresponding flag objects.
type FlagMap = Record<string, Flag>.enabled vs .value
.enabledis a boolean, indicating whether the flag is turned on..valueis the string obtained by evaluating the rules of the flag.- If a flag is disabled, the
.valuewill always be''(empty string). - If a flag is enabled, the
.valuewill be the result value of the first satisfied rule. - If a flag has no rules, or if no rule is satisfied, the
.valuewill be''(empty string).
- If a flag is disabled, the
Only POST requests of type application/json are expected.
Endpoint: /exapi/evalFlags
Request Data:
mode:"test"or"live"traits: A plain object describing the user, with only string or number values.- Eg:
{"userId": "00c13408a...", "plan": "premium", "projectCount": 10}
- Eg:
Successful Response Shape:
{status: "success", data: FlagMap}(See FlagMap shape above)
CURL snippet:
curl --request POST \
--url http://localhost:3333/exapi/evalFlags \
--header 'content-type: application/json' \
--data '{"mode": "test", "traits": {}}'Endpoint: /exapi/evalFlag
Request Data:
flag_id: stringmode:"test"or"live"traits: A plain object describing the user, with only string or number values.- Eg:
{"userId": "00c13408a...", "plan": "premium", "projectCount": 10}
- Eg:
Successful Response Shape:
{status: "success", data: Flag}(See Flag shape above)
-
To subscribe to realtime updates, you can point a Socket.IO client to your FlagLeap server (
instanceUrl). -
Whenever a flag (potentially) changes, the server emits a
'flagNotifFromServer'event. -
The associated data has two properties:
flag_id: string ID of the flagmode: either 'test' or 'live'
-
Upon receiving a
flagNotifFromServer, you should use the/exapi/evalFlagendpoint to re-evaluate that flag. -
If you're using one of the SDKs, then there's you needn't do this manually. The SDK will handle this for you.
npm install flagleap in your app, and then:
import { flagleapSdk } from 'flagleap'
// Create a flagleap client:
const flagleap = flagleapSdk.flagleapClient({
instanceUrl: "http://localhost:3333",
mode: "test",
})
// Optionally set user-traits for user-specific flag evaluations.
// This may be done right away, or as/when a user logs in.
flagleap.setTraits({
userId: 'user_1234',
plan: 'premium',
// ... etc ...
})
// Initialize the client and call `.getFlag()` for getting flags!
flagleap.init().then(function () {
const isFooEnabled = flagleap.getFlag('enableFoo').enabled
})
// When the user logs out, you may want to:
flagleap.setTraits({})- To use the JS/TS SDK on Node,
npm install node-fetch(or another isomorphicfetchfunction). - And supply it (dependency injection) to flagleap via
flagleapSdk.injectIsomorphicFetch(fetch).
- To subscribe to realtime notifications regarding (potential) flag updates, use
.subscribe():
flagleap.subscribe(() => {
// This will be called whenever a flag changes.
})npm install flagleap in your app, and then:
flag-store.ts
import { React } from 'react'
import { flagleapSdk } from 'flagleap'
// Create a flagleap client:
const flagleap = flagleapSdk.flagleapClient({
instanceUrl: "http://localhost:3333",
mode: "test",
})
// Pass your version of React (>= 16.8) to generate a hook.
const useFlag = flagleapSdk.makeUseFlag(flagleap, React)
export { flagleap, useFlag }And call useFlag in your components:
Counter.tsx
import { React } from 'react'
import { useFlag } from './flag-store'
export const Counter: React.VFC = () => {
const [count, setCount] = React.useState(0)
const addTwoEnabled = useFlag('enableAddTwo').enabled
return (
<div>
Count: {count}
<button onClick={() => setCount(count + 1)}>Add 1</button>
{addTwoEnabled && (
<button onClick={() => setCount(count + 2)}>Add 2</button>
)}
</div>
)
}Use the FlagLeap UI to (create and) enable the enableAddTwo flag. Toggling the flag will toggle the Add 2 button in your app.

