Test feature flags with different SDKs - see code examples and live evaluation
This demo tests your Rollgate feature flags in real-time.
Setup:
Modes:
Evaluation:
Tips:
npm install @rollgate/react
import { RollgateProvider } from '@rollgate/react';
function App() {
return (
<RollgateProvider
apiKey="rg_client_xxxxx"
options={{ polling: 30000 }}
>
<YourApp />
</RollgateProvider>
);
}import { useFlag, useFlags } from '@rollgate/react';
function MyComponent() {
// Single flag
const darkMode = useFlag('dark-mode');
// Multiple flags
const { flags, isLoading } = useFlags();
if (darkMode) {
return <DarkTheme />;
}
return <LightTheme />;
}import { useRollgate } from '@rollgate/react';
function UserProfile() {
const { identify } = useRollgate();
useEffect(() => {
identify({
userId: 'user-123',
attributes: {
plan: 'pro',
country: 'IT'
}
});
}, []);
}npm install @rollgate/vue
import { createApp } from 'vue';
import { RollgatePlugin } from '@rollgate/vue';
const app = createApp(App);
app.use(RollgatePlugin, {
apiKey: 'rg_client_xxxxx',
polling: 30000
});
app.mount('#app');<script setup>
import { useFlag, useFlags } from '@rollgate/vue';
const darkMode = useFlag('dark-mode');
const { flags, isLoading } = useFlags();
</script>
<template>
<DarkTheme v-if="darkMode" />
<LightTheme v-else />
</template>npm install @rollgate/angular
import { RollgateModule } from '@rollgate/angular';
@NgModule({
imports: [
RollgateModule.forRoot({
apiKey: 'rg_client_xxxxx',
polling: 30000
})
]
})
export class AppModule {}import { RollgateService } from '@rollgate/angular';
@Component({ ... })
export class MyComponent {
darkMode$ = this.rollgate.getFlag('dark-mode');
constructor(private rollgate: RollgateService) {}
}<div *rgFlag="'new-feature'">
This content is shown when new-feature is enabled
</div>npm install @rollgate/svelte
<script>
import { initRollgate } from '@rollgate/svelte';
initRollgate({
apiKey: 'rg_client_xxxxx',
polling: 30000
});
</script><script>
import { getFlag, flags } from '@rollgate/svelte';
const darkMode = getFlag('dark-mode');
</script>
{#if $darkMode}
<DarkTheme />
{:else}
<LightTheme />
{/if}npm install @rollgate/sdk-node
import { RollgateClient } from '@rollgate/sdk-node';
const client = new RollgateClient({
apiKey: 'rg_server_xxxxx',
polling: 30000
});
// Check a flag
const isEnabled = await client.isEnabled('dark-mode');
// With user context
const result = await client.isEnabled('premium-feature', {
userId: 'user-123',
attributes: { plan: 'pro' }
});import express from 'express';
const app = express();
app.use(async (req, res, next) => {
req.flags = await client.getAllFlags({
userId: req.user?.id,
attributes: { plan: req.user?.plan }
});
next();
});
app.get('/api/features', (req, res) => {
if (req.flags['new-api']) {
return res.json({ version: 'v2' });
}
res.json({ version: 'v1' });
});pip install rollgate
from rollgate import RollgateClient
client = RollgateClient(
api_key="rg_server_xxxxx",
polling_interval=30
)
# Check a flag
if client.is_enabled("dark-mode"):
print("Dark mode is on!")
# With user context
result = client.is_enabled(
"premium-feature",
user_id="user-123",
attributes={"plan": "pro"}
)from rollgate import AsyncRollgateClient
import asyncio
async def main():
client = AsyncRollgateClient(api_key="rg_server_xxxxx")
is_enabled = await client.is_enabled("new-feature")
await client.close()
asyncio.run(main())