• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
No results for ""
EXPAND ALL

EDIT ON GITHUB

Getting all flags

Read time: 5 minutes
Last edited: May 20, 2022

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.

Understanding the all flags feature

The all flags feature returns the state of all feature flags targeted to a user. This includes the flag values, and, for server-side SDKs, metadata for use on the front end.

In most of the client- and server-side SDKs, getting all flags does not create users or other analytics events in your LaunchDarkly account. Unlike evaluating individual flags or identifying users, getting all flags usually does not send events that create a user within LaunchDarkly or populate the flag evaluations graph for a flag.

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 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 our 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
  • Server-side SDKs

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)

Expand .NET (client-side) code sample

The AllFlags method produces a map of feature flag keys to their values for the current user:

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 for a specific user:

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 for a specific user:

Map<String, LDValue> flagValues = await LDClient.allFlags();

To learn more, read the API documentation.

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 returns a key/value map of all your feature flags.

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 with the sendEventsOnlyForVariation configuration option.

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 returns a key/value map of all your feature flags.

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 with the sendEventsOnlyForVariation configuration option.

let allFlagsResult = client.allFlags();

To learn more, read the API documentation.

React

All 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 an object containing flag keys and values. 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 Listener
let 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 -> 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)

Expand .NET (server-side) code sample

The AllFlagsState 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:

var state = client.AllFlagsState(user);

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 user. This includes their values and other metadata.

To use the all flags feature:

ldclient:all_flags_state(#{key => <<"aa0ceb">>})

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 user. 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 (
"gopkg.in/launchdarkly/go-server-sdk.v5/interfaces/flagstate"
)
state := client.AllFlagsState(user, 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 user. This includes their values, as well as other metadata.

To use the all flags feature:

state = allFlags client user

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 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:

FeatureFlagsState state = client.allFlagsState(user);

To learn more, read the API documentation.

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 user. This includes their values, as well as other metadata.

To use the all flags feature:

client.allFlagsState(user, options, (err, flagsState) => {
// this object can be converted to JSON or can be queried for flag values
});

To learn more, read the API documentation.

Node.js (Cloudflare)

This SDK uses the same code as the Node.js server-side SDK.

PHP

Expand PHP code sample

The allFlagsState 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 = $client->allFlagsState($user);

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(user)

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 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 = client.all_flags_state(user)

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 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:

let state = ldclient.all_flags_detail(&user, FlagDetailConfig::new());

To learn more, read the API documentation.