No results for ""
EXPAND ALL
  • Home
  • API docs

Setting up an SDK

Read time: 4 minutes
Last edited: May 01, 2024

Overview

This topic explains how to set up an SDK to begin using LaunchDarkly.

Prefer to set up your SDK interactively?

Try our Quickstart guide or CLI to set up your first flag, SDK, and sample application.

Setting up an SDK

The steps to integrate your application with LaunchDarkly are similar across all SDKs. We provide a variety of server-side, client-side, mobile, and edge SDKs to choose from. To learn more about choosing an SDK, read Client-side, server-side, and edge SDKs.

We provide reference documentation for all SDKs under SDKs, including how to get started with each SDK and where to find SDK API documentation, sample applications, public GitHub repositories, and published modules.

Setting up an SDK is similar no matter which SDK you choose. Find specifics in the reference documentation for each SDK.

To incorporate a LaunchDarkly SDK into your application:

  1. Install the LaunchDarkly SDK in your application using your project's dependency manager. This lets your application access the LaunchDarkly SDK.
  1. Initialize the LaunchDarkly client in your application code. This client is the primary way your application uses the SDK and communicates with LaunchDarkly.
  2. Configure the LaunchDarkly client with the appropriate key for your environment. Your SDK key, client-side ID, and mobile key uniquely identify your project and environment, and they authorize your application to connect to LaunchDarkly. In most SDKs, you set this configuration during the initialization step.
  3. Evaluate each feature flag for a specific context. A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. You can set the attributes for each context in your application. Every feature flag is uniquely identified by a feature flag key. Each SDK provides methods to take the flag key and context and determine which flag variation each context should receive.
Adding contexts to LaunchDarkly

You don't have to send contexts to LaunchDarkly in advance. After you create contexts in your SDK, you can target them with feature flags before they appear on your Contexts list. Contexts that exist in your SDK appear in the Contexts list automatically after they encounter feature flags.

  1. Shut down the LaunchDarkly client when your application is about to terminate. The client releases the resources it is using and sends pending analytics events to LaunchDarkly, if any. If your application quits without this shutdown step, requests and the Contexts list may not be populated, because they are derived from analytics events.

Editor support

SDK documentation appears in your editor if the editor supports surfacing doc comments. LaunchDarkly offers further integrations for VSCode or IntelliJ IDEA.

These integrations have extended functionality based on Code References aliases. If your team uses aliases to find all flag usage throughout your codebase, you will also have hover documentation wherever those aliases appear. To learn more, read Code references.

Flag evaluations are always available

If the SDK you use loses the connection with LaunchDarkly, your feature flags will still work. The SDK relies on its stored state to evaluate flags. No network communication is required when you evaluate a flag.

By default, an SDK initializes with an empty state. When the SDK first initializes, it opens a streaming connection to LaunchDarkly. The response from LaunchDarkly contains the SDK's current state, which your SDK uses to make any necessary changes to feature flags. After the initial update, the SDK keeps a streaming connection open to LaunchDarkly. If you make a change in the flags list or with the REST API, LaunchDarkly sends these changes to all connected SDKs automatically.

If you evaluate a flag before the SDK receives its initial state, or you try to fetch a flag which otherwise doesn't exist, then the SDK returns a fallback value. You can specify the fallback value in your flag evaluation code. SDKs may periodically drop streaming connections. When an SDK loses connectivity to LaunchDarkly, it continues to try to reestablish a streaming connection until it succeeds. To learn more about how SDKs handle streaming connections, read Receiving updates from LaunchDarkly.

All SDKs provide synchronous and asynchronous ways of waiting for the SDK's state to initialize.

Next steps

After you have set up an SDK, you can manage features on your flags list. To learn more, read The flags list.

When you're ready to test your application, use the Live events page to get a real-time view of your feature flag requests as they're received. To learn more, read Live events.

As you begin using feature flags, here are some useful features you can use without re-deploying your application: