Skip to main content

Using Feature Flags In Code

Overview

This guide provides a high-level overview on using Feature Flags in your application. For a more detailed guide on a particular SDK, refer to the SDK documentation.

Providing User Data

When getting Feature Flags from the AppFlags client, you need to provide some data about your user. At minimum, you need to provide a unique key for each of your users. This is a string that must be unique for each user and not change.

For example, in Javascript, a basic user looks like this:

const user = {
key: "<unique_user_key>"
};

In a client-side SDK, you need to provide user information when initializing the AppFlags client.

In a server-side SDK, you need to provide user information when getting Feature Flags.

Getting Feature Flags

You can get a Feature Flag from the AppFlags client by specifying the flag's key.

For example, in Javascript, getting a Feature Flag looks like this:

const flag = appflagsClient.getFlag("flag_key");

In a server-side SDK, you will also need to specify the user. For example, in Node.js, getting a Feature Flag looks like this:

const flag = appflagsClient.getFlag(user, "flag_key");

For more details on getting Feature Flags and additional SDK functionality, refer to the SDK documentation for the specific SDK that you are using.

Getting Realtime Feature Flag Updates

When you modify a Feature Flag in the AppFlags dashboard, the AppFlags client in your application immediately receives the updated Feature Flag. This allows your app to immediately react to Feature Flag changes.

Client-side SDK Realtime Updates

In a client-side SDK, you can set up a callback to get notified when a particular Feature Flag is modified for the user.

For example, in Javascript, you can subscribe to Feature Flag updates with a callback like this:

appFlagsClient.onFlagChanged("flag_key", flag => {
// handle the updated feature flag
});

Server-side SDK Realtime Updates

In a server-side SDK, you can set up a callback to get notified when any Feature Flags have been updated.

For example, in Node, you can subscribe to Feature Flag updates with a callback like this:

appflagsClient.onFlagsChanged(() => {
// handle flags changing
});

Additional SDK Functionality

The above examples highlight a few basic uses of the AppFlags SDK. For a full reference, refer to the SDK documentation.