SDKs Overview
Learn with runnable samplesβ
Start with the Toggly.Samples catalog. Each available sample includes setup, a first-toggle exercise, source files to read, and tests. Choose an available example that matches your framework and follow its README.
A flag key identifies a decision; its environment selects the definitions to load. Start with local defaults, observe both the enabled and disabled paths, then follow the sample's separate dashboard provisioning steps. Offline fixture results do not prove live connectivity.
Toggly provides SDKs for multiple platforms and languages. All SDKs share common concepts and patterns.
Available SDKsβ
- JavaScript: JavaScript and frontend framework SDKs (Vanilla JS, React, Angular, Vue.js, Svelte)
- Blazor: SSR, Interactive Server, WebAssembly and Auto
- NestJS: HTTP modules, request-scoped services and feature guards
- .NET: .NET and .NET Core applications
- Elixir / Phoenix / LiveView: Supervised local evaluation and request/socket context
- Go: Go server-side SDK (local evaluation)
- PHP: PHP applications with Laravel and WordPress support
- Java: Java applications
- Python: Python applications
- Node.js: Node.js server-side applications
- Rust: Rust applications
- Ruby / Rails: Ruby and Ruby on Rails applications
- Flutter: Flutter applications
- CSS / HTML: Show or hide HTML with a generated stylesheet (no JavaScript)
- iOS (Swift): Native iOS, macOS, tvOS, and watchOS applications
- Android (Kotlin): Native Android applications with Jetpack Compose and Views support
- React Native: React Native and Expo applications
- Electron: Electron desktop applications (main + renderer)
- Next.js: Next.js 14+ App Router with Server, Client, and Edge support
- React Router: React Router 7/8 framework mode with full SSR support
- Remix (deprecated): migrate to the React Router SDK
- Nuxt: Nuxt 3 and Nuxt 4 applications with SSR/SSG and auto-imported composables
- Docusaurus: Docusaurus plugin for documentation gating
- Astro: Astro integration with SSR/SSG support and framework wrappers
- Gatsby: Gatsby applications with SSR/SSG and build-time page gating
- WordPress: WordPress plugin (settings, shortcodes,
toggly_is_enabled, WP-Cron)
CLI Toolβ
The Toggly CLI is a powerful command-line tool for automating Toggly operations. Perfect for CI/CD pipelines, it enables you to:
- Create and manage releases
- Associate CI builds with releases
- Create and update feature flags
- Update feature configurations across environments
- Integrate seamlessly with GitHub Actions, Azure DevOps, and other CI/CD platforms
π Get started with the CLI β
Hooksβ
JavaScript SDKs can register lifecycle callbacks for analytics (Clarity, GA4, Application Insights) and custom integrations. Hooks are documented here; they are not a create-app Technology Stack.
Common Conceptsβ
- Generic browser client β framework-independent client-core setup and cleanup
- Frontend telemetry β compact feature checks, explicit usage/views, counters and gauges, optional minted
i/ clientu - SDK Γ filter matrix β which filters each SDK evaluates (worker vs local vs fail-closed)
- Syncing segment membership β shared flow; each server SDK page shows that libraryβs client
- Support floors β canonical runtime minima (Java 17, Go 1.24, Rust 1.88, β¦)
- Server-side reliability β shared snapshot / signature contract
Initializationβ
All SDKs require initialization with your App Key:
// Example: JavaScript
Toggly.init({
appKey: 'your-app-key',
environment: 'production'
});
Feature Evaluationβ
Evaluate feature flags:
// Boolean evaluation
if (Toggly.isFeatureOn('my-feature')) {
// Feature is enabled
}
User Contextβ
Provide user context for targeting and rollouts:
Toggly.init({
appKey: 'your-app-key',
environment: 'production',
userIdentifier: 'user-123'
});
Cachingβ
SDKs cache feature flags to reduce API calls:
- Cache Duration: Configurable cache TTL (default: 3 minutes for definitions, 30 minutes for user sessions)
- Cache Invalidation: Automatic on updates
- Offline Support: Use cached values when offline
Device-local master switches can further gate cached remote booleans at read time β see Post-filter gates. Live updates use WebSocket sync with a shared definitions revision.
Error Handlingβ
SDKs handle errors gracefully:
- Network Errors: Fall back to cached values or defaults
- Invalid Responses: Fall back to default values
- Flag Defaults: Set default values for offline scenarios
Best Practicesβ
1. Use Environment Variablesβ
Store App Keys in environment variables or configuration:
TOGGLY_APP_KEY=your-app-key
TOGGLY_ENVIRONMENT=production
2. Initialize Onceβ
Initialize the SDK once and reuse the instance:
// Good: Initialize once
Toggly.init({...});
// Bad: Initialize multiple times
Toggly.init({...});
Toggly.init({...}); // Don't do this
3. Handle Errorsβ
Always handle errors and provide defaults:
// Set flag defaults for offline scenarios
Toggly.init({
appKey: 'your-app-key',
environment: 'production',
flagDefaults: {
'my-feature': false // Default to disabled if offline
}
});
4. Use Cachingβ
Feature definitions are automatically cached and refreshed periodically.
5. Provide User Contextβ
Include user identifiers for accurate targeting and consistent rollouts:
Toggly.init({
appKey: 'your-app-key',
environment: 'production',
userIdentifier: 'unique-user-id'
});
Cheat Sheetsβ
Looking for a quick reference? Every SDK ships with a printable two-page cheat sheet covering install, init, evaluation, framework integrations, and common pitfalls.
Next Stepsβ
Choose your platform and follow the specific SDK guide:
- CLI Tool - Automate Toggly operations from the command line
- Hooks
- JavaScript SDKs
- .NET SDK
- Go SDK
- PHP SDK
- Svelte SDK
- SvelteKit SDK β server hooks, loads/actions and SSR hydration
- SolidJS SDK
- SolidStart SDK
- Flutter SDK
- CSS / HTML
- Docusaurus plugin
- iOS SDK
- Android SDK
- React Native SDK
- Next.js SDK
- React Router SDK
- Remix SDK (deprecated)
- Nuxt SDK
- Astro SDK
- Gatsby SDK
- WordPress