Getting all flags
Read time: 6 minutes
Last edited: May 17, 2023
Overview
This topic explains how the all flags feature works in the LaunchDarkly SDKs that support it. The all flags feature is available for both client-side and server-side SDKs.
A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. Contexts replace another data object in LaunchDarkly: "users."
Creating contexts and evaluating flags based on them is supported in the latest major versions of most of our SDKs. For these SDKs, the code samples on this page include the two most recent versions.
Understanding the all flags feature
The all flags feature returns the state of all feature flags targeted to a context or user. This includes the flag values, and, for server-side SDKs, metadata for use on the front end.
The all flags method does not send analytics events to LaunchDarkly by default for most SDKs. The exceptions to this are Electron, JavaScript, Node.js (client-side), and Vue, which do send analytics events by default. For these SDKs, you can disable sending analytics events when calling the all flags method if needed. To learn more about what analytics events do in LaunchDarkly, read Analytics events.
For client-side SDKs, the all flags feature may return a null value in cases where a flag's fallback value would be served to the end user.
For server-side SDKs, you can use the all flags feature to pass feature flags to your front end. In particular, you can use it to provide bootstrap flag settings for the JavaScript SDK. To learn more about bootstrapping from a client-side SDK, read Bootstrapping.
Details about each SDK's configuration are available in the SDK-specific sections below:
Client-side SDKs
Before you implement this feature, read Understanding the all flags feature.
This feature is available in the following client-side SDKs:
- .NET (client-side)
- Android
- Electron
- Flutter
- iOS
- JavaScript
- Node.js (client-side)
- React: The React SDK relies on the JavaScript SDK for this functionality.
- React Native
- Roku
.NET (client-side)
Expand .NET (client-side) code sample
The AllFlags
method produces a map of feature flag keys to their values:
client.AllFlags();
To learn more, read the API documentation.
Android
Expand Android code sample
The allFlags
method produces a map of feature flag keys to their values:
client.allFlags();
To learn more, read the API documentation.
Electron
Expand Electron code sample
The allFlags()
method produces a map of feature flag keys to their values. The map contains null values for any flags that would return the fallback value. The fallback value is the second argument that you normally pass to variation
.
Unlike most of our SDKs, our Electron SDK's allFlags()
method sends analytics events to LaunchDarkly. If you do not want allFlags()
to generate any analytics events, you can turn this off by setting the configuration option sendEventsOnlyForVariation
to true
.
To use the all flags feature:
let allFlagsResult = client.allFlags();
To learn more, read the API documentation.
Flutter
Expand Flutter code sample
The allFlags
method produces a map of feature flag keys to their values:
Map<String, LDValue> flagValues = await LDClient.allFlags();
To learn more, read allFlags
.
iOS
Expand iOS code sample
All flags returns a dictionary with the flag keys and their values. If the LDClient
is not started, it returns nil
.
To use the all flags feature:
let allFlags: [String: LDValue] = LDClient.get()!.allFlags
To learn more, read the API documentation for Swift or Objective-C.
JavaScript
Expand JavaScript code sample
The allFlags()
method produces a map of feature flag keys to their values.
The map contains null values for any flags that would return the fallback value. The fallback value is the second argument that you normally pass to variation
.
Unlike most of our SDKs, our JavaScript SDK's allFlags
method sends analytics events to LaunchDarkly. If you do not want allFlags
to generate any analytics events, you can turn this off by setting the configuration option sendEventsOnlyForVariation
to true
.
To use the all flags feature:
let allFlagsResult = client.allFlags();
To learn more, read the API documentation.
Node.js (client-side)
Expand Node.js (client-side) code sample
The allFlags
method produces a map of feature flag keys to their values.
The map contains null values for any flags that would return the fallback value. The fallback value is the second argument that you normally pass to variation
.
Unlike most of our SDKs, our Node.js (client-side) SDK's allFlags
method sends analytics events to LaunchDarkly. If you do not want allFlags
to generate any analytics events, you can turn this off by setting the sendEventsOnlyForVariation
option to true
.
To use the all flags feature:
let allFlagsResult = client.allFlags();
To learn more, read the API documentation.
React
All context- and user-related functionality provided by the JavaScript SDK is also available in the React SDK after you have initialized the SDK and have an ldClient
available.
React Native
Expand React Native code sample
The allFlags
method returns a map containing all flag keys and values for the current context. You can also register a listener that fires when any flag in your environment changes.
To use the all flags feature:
let allFlagsResult = client.allFlags();allFlagsResult.then(values => {console.log(values);});// All Flags Listenerlet listenerId = 'ARBITRARY_VALUE'let listener = value => Alert.alert('All Flags Listener Callback', value);client.registerAllFlagsListener(listenerId, listener);
To learn more, read the API documentation.
Roku
Expand Roku code sample
You can get an associative array of flagKey
to flagValue
for all flags from the client with:
allFlags = launchDarkly.allFlags()
Server-side SDKs
Before you implement this feature, read Understanding the all flags feature.
This feature is available in the following server-side SDKs:
- .NET (server-side)
- Apex
- C/C++ (server-side)
- Erlang
- Go
- Haskell
- Java
- Lua
- Node.js (server-side)
- PHP
- Python
- Ruby
- Rust
.NET (server-side)
Expand .NET (server-side) code sample
The AllFlagsState
method captures the state of all feature flags with regard to a specific context. This includes the flag values, as well as other metadata.
To use the all flags feature:
var state = client.AllFlagsState(context);
To learn more, read the API documentation.
Apex
Expand Apex code sample
The allFlags
method produces a map of feature flag keys to their values for a specific user. This does not send any evaluation events to LaunchDarkly.
To use the all flags feature:
Map<String, LDValue> values = client.allFlags(user);
To learn more, read the API documentation.
C/C++ (server-side)
Expand C/C++ (server-side) code sample
The LDAllFlags
function captures the state of all feature flag keys with regard to a specific user. This includes their values, as well as other metadata.
This method can be useful for passing feature flags to your front end. In particular, it can be used to provide bootstrap flag settings for our JavaScript SDK.
To use the all flags feature:
struct LDJSON *allFlags = LDAllFlags(client, user);
To learn more, read the API documentation.
Erlang
Expand Erlang code sample
The all_flags_state
function captures the state of all feature flag keys as evaluated for a specific context. This includes their values and other metadata.
To use the all flags feature:
ldclient:all_flags_state(#{key => <<"context-key-123abc">>})
To learn more, read the API documentation.
Go
Expand Go code sample
The AllFlagsState
method captures the state of all feature flag keys with regard to a specific context. This includes their values, as well as other metadata.
In this example, the extra ClientSideOnly
option is specified so that only the feature flags designated for client-side use are included in the result.
To use the all flags feature:
import ("github.com/launchdarkly/go-server-sdk/v6/interfaces/flagstate")state := client.AllFlagsState(context, flagstate.OptionClientSideOnly())
To learn more, read the API documentation.
Haskell
Expand Haskell code sample
The allFlags
function captures the state of all feature flag keys as evaluated for a specific context. This includes their values, as well as other metadata.
To use the all flags feature:
state = allFlagsState client context False False False
To learn more, read the API documentation.
Java
Expand Java code sample
The allFlagsState
method captures the state of all feature flags with regard to a specific context. This includes their values as well as other metadata.
This method can be useful for passing feature flags to your front end. In particular, it can be used to provide bootstrap flag settings for our JavaScript SDK.
To use the all flags feature:
FeatureFlagsState state = client.allFlagsState(context);
To learn more, read allFlagsState
.
Lua
Expand Lua code sample
The allFlags
method captures the state of all feature flag keys with regard to a specific user. This includes their values, as well as other metadata.
To use the all flags feature:
local allFlags = client:allFlags(user)
To learn more, read the API documentation.
Node.js (server-side)
Expand Node.js (server-side) code sample
The allFlagsState
method captures the state of all feature flag keys with regard to a specific context. This includes their values, as well as other metadata.
To use the all flags feature:
client.allFlagsState(context, options, (err, flagsState) => {// this object can be converted to JSON or can be queried for flag values});
To learn more, read the API documentation.
PHP
Expand PHP code sample
The allFlagsState
method captures the state of all feature flag keys with regard to a specific context. This includes their values, as well as other metadata.
This method can be useful for passing feature flags to your front end. In particular, you can use it to provide bootstrap flag settings for LaunchDarkly's JavaScript SDK.
To use the all flags feature:
$state = $client->allFlagsState($context);
To learn more, read the API documentation.
Python
Expand Python code sample
The all_flags_state
method captures the state of all feature flag keys with regard to a specific user. This includes their values, as well as other metadata.
This method can be useful for passing feature flags to your front end. In particular, it can be used to provide bootstrap flag settings for our JavaScript SDK.
To use the all flags feature:
state = ldclient.get().all_flags_state(context)
To learn more, read the API documentation.
Ruby
Expand Ruby code sample
The all_flags_state
method captures the state of all feature flag keys with regard to a specific context. This includes their values, as well as other metadata.
This method can be useful for passing feature flags to your front end. In particular, it can be used to provide bootstrap flag settings for our JavaScript SDK.
To use the all flags feature:
state = client.all_flags_state(context)
To learn more, read the API documentation.
Rust
Expand Rust code sample
The all_flags_detail
method captures the state of all feature flag keys with regard to a specific context. This includes their values, as well as other metadata.
This method can be useful for passing feature flags to your front end. In particular, it can be used to provide bootstrap flag settings for our JavaScript SDK.
To use the all flags feature:
let state = ldclient.all_flags_detail(&context, FlagDetailConfig::new());
To learn more, read the API documentation.
Edge SDKs
This feature is available for all of our edge SDKs:
Cloudflare
Expand Cloudflare code sample
The allFlagsState
method captures the state of all feature flag keys with regard to a specific context. This includes their values, as well as other metadata.
To use the all flags feature:
const allFlags = await client.allFlagsState(context);
To learn more, read the API documentation.
Vercel
Expand Vercel code sample
The allFlagsState
method captures the state of all feature flag keys with regard to a specific context. This includes their values, as well as other metadata.
To use the all flags feature:
const allFlags = await client.allFlagsState(context);
To learn more, read allFlagsState
.