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

EDIT ON GITHUB

Getting all flags

Read time: 5 minutes
Last edited: Jan 25, 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 analytic 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 "Insights" for a flag.

For client-side SDKs, the all flags feature may return a null value in cases where a flag's fallback variation 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)

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

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

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

All flags returns a dictionary with the flag keys and their values. If the LDClient is not started, it returns nil.

The dictionary does not contain feature flags from the server with null values. LDClient does not provide any source or change information, only flag keys and flag values. The client app should convert the feature flag value into the desired type.

To use the all flags feature:

let allFlags = LDClient.get()!.allFlags

To learn more, read the API documentation.

JavaScript

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 analytic events to LaunchDarkly. If you do not want allFlags to generate any analytic 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)

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 analytic events to LaunchDarkly. If you do not want allFlags to generate any analytic events, you can turn this off with the sendEventsOnlyForVariation configuration option.

let allFlagsResult = client.allFlags();

To learn more, read the API documentation.

React Native

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

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)

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

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)

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

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

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

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

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

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)

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, (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

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

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

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

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.