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

GIVE DOCS FEEDBACK

Akamai SDK reference

Read time: 4 minutes
Last edited: Jan 29, 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.

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

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

Getting started

To install and configure the Akamai SDK if you are using Akamai EdgeKV:

  1. Complete the Creating an Akamai integration procedure.

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

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

    import { init } from '@launchdarkly/akamai-server-edgekv-sdk';
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. Your environment's client-side ID is available in the Projects tab of your Account settings page. To learn more about key types, read Keys.

  1. 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'
    });
  2. 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);
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 Creating 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.

Shutting down

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

Supported features

This SDK supports the following features: