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

Akamai SDK reference

Read time: 5 minutes
Last edited: Oct 30, 2024

Overview

This topic documents how to get started with the Akamai SDK, and links to reference information on all of the supported features.

SDK quick links

LaunchDarkly's SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:

ResourceLocation
SDK API documentationSDK API docs
GitHub repositoryLaunchDarkly Akamai SDK

The Akamai SDK is designed to be used with one of the LaunchDarkly client-side SDKs as follows:

  • The Akamai SDK gets all flags at the edge for a given context, and bootstraps them onto a cached payload
  • The client-side SDK initializes the bootstrapped payload
  • The client-side SDK evaluates the flags and sends events back to LaunchDarkly
Using this SDK with Akamai EdgeKV requires LaunchDarkly's Akamai integration

If you are using Akamai EdgeKV, configure the Akamai integration to use this SDK successfully. To learn more, read Akamai.


The Akamai integration is available to customers on an Enterprise plan. To learn more, read about our pricing. To upgrade your plan, contact Sales.


If you are using Akamai's EdgeWorkers, but not using the Akamai EdgeKV, the Akamai integration is not required.

Get started

After you complete the Create an Akamai integration process in an existing project, follow these instructions to start using the LaunchDarkly Akamai SDK if you are using Akamai EdgeKV:

Most customers use the Akamai EdgeKV and the Akamai integration. If you are using Akamai's EdgeWorkers, but not using the Akamai EdgeKV store, you can use the LaunchDarkly Akamai SDK to access your own feature store instead. If you are using your own feature store, skip to Using Akamai EdgeWorkers with your own feature store, below.

Install the SDK

Install the Akamai SDK as a dependency in your application using your application's dependency manager:

yarn add @launchdarkly/akamai-server-edgekv-sdk

Then, import the init method in your application code:

import { init } from '@launchdarkly/akamai-server-edgekv-sdk';

Initialize the client

After you install and import the SDK, initialize the client with your LaunchDarkly SDK client-side ID and the namespace and group from your Akamai EdgeKV. These should be the same namespace and group that you used to configure the Akamai integration.

Here's how:

const ldClient = init({
sdkKey: 'client-side-id-123abc',
namespace: 'your-edgekv-namespace',
group: 'your-edgekv-group-id'
});
The Akamai SDK uses a client-side ID

The Akamai SDK uses a client-side ID to associate the LaunchDarkly environment with the CDN integration. Client-side IDs are specific to each project and environment. They are available from the Environments list for each project. To learn more about key types, read Keys.

Evaluate a flag

Using the client, check which variation a particular context will receive for a given feature flag:

import { LDContext } from '@launchdarkly/akamai-server-edgekv-sdk';
const context: LDContext = {
kind: 'org',
key: 'org-key-123abc',
someAttribute: 'example-attribute-value',
};
const flagValue = await ldClient.variation('flag-key-123abc', context, false);

Using Akamai EdgeWorkers with your own feature store

Expand for instructions if you are using Akamai EdgeWorkers with a non-EdgeKV store

Most customers use the Akamai EdgeKV and the Akamai integration. If you are using Akamai's EdgeWorkers, but not using the Akamai EdgeKV store, you can use the LaunchDarkly Akamai SDK to access your own feature store instead. However, the package and method names are slightly different. Additionally, you are responsible for putting flag data into your EdgeWorker. LaunchDarkly does not provide an integration for this.

To install and configure the Akamai SDK if you are using Akamai EdgeWorkers with a non-EdgeKV store:

  1. Install the Akamai SDK as a dependency in your application using your application's dependency manager:

    yarn add @launchdarkly/akamai-server-base-sdk
  2. Import the init method in your application code:

    import { init } from '@launchdarkly/akamai-server-base-sdk';
  3. Create a new class that implements EdgeProvider. It should take a key, formatted as LD-Env-{your LaunchDarkly client-side ID for this environment}. It should return a promise to return flag data. To learn more about how to retrieve and store flag data, read Create a flag data file. To learn more, read EdgeProvider.

    Here's an example:

    import { EdgeProvider } from '@launchdarkly/akamai-server-base-sdk';
    class FeatureStore implements EdgeProvider {
    // rootKey is formatted as LD-Env-{LaunchDarkly client-side ID}
    async get(rootKey: string): Promise<string> {
    // You should provide an implementation to retrieve your flags from
    // LaunchDarkly's https://sdk.launchdarkly.com/sdk/latest-all endpoint.
    // Read https://docs.launchdarkly.com/sdk/features/flags-from-files for more information.
    return flagData;
    }
    }
  4. After you install and import the SDK, initialize the client with your LaunchDarkly SDK client-side ID and an instance of the class you created in the previous step.

    Here's how:

    const ldClient = init({
    sdkKey: 'client-side-id-123abc',
    featureStoreProvider: new FeatureStore(),
    });
  5. Using the client, check which variation a particular context will receive for a given feature flag:

    import { LDContext } from '@launchdarkly/akamai-server-base-sdk';
    const context: LDContext = {
    kind: 'org',
    key: 'org-key-123abc',
    someAttribute: 'example-attribute-value',
    };
    const flagValue = await ldClient.variation('flag-key-123abc', context, false);

Promises and async

All asynchronous SDK methods that return a Promise are compatible with then/catch or async/await. You can use either.

Shut down the client

In the Akamai SDK, the client will be automatically closed when your application terminates.

Supported features

This SDK supports the following features: