Quick Start

Get started using the Toggle service

Toggle is a seamless feature release management system built on the robust OpenFeature standard. Hyphen publishes openFeature providers for the most common languages, but our Toggle services supports and documents an open API allowing you to consume it how you see fit.

Toggles are grouped and belong to a Hyphen Project; Targeting can be used to provide different values for a project's applications and environments.

Get a Project's Public Key

To use Toggle, you will need a project public key. To get the public key for a project:

  1. Navigate to your Hyphen Dashboard.
  2. Select your Project from the list.
  3. Go to the Access tab.
  4. Copy the Public Key for your project.

All public keys start with public_ to make them easy to identify.

Creating a Feature Flag

  1. From the Project Details page, navigate to Toggles, then Create Feature Flag button.
  2. Select a type, provide a key (for SDK references), and set a logical default value.
  3. While optional, adding a clear description helps team members understand the toggle’s purpose.
  4. Click Create to save, which redirects you to the feature flag detail page.

This page contains Telemetry information and also you to configure targets.

Targeting

  1. On the feature flag detail page scroll down to the Targets sections can click Add a Target.
  2. In the drawer you can choose one more more target criteria, values from the context, to evaluate on and then provide that resulting value.

Feature flags can include multiple targets. Evaluation proceeds sequentially—from the first target to the last—and stops as soon as a match is found. At that point, the matching target’s value is returned. (Targets can be reordered within the application.)

ℹ️

It is recommended to use the context's application and environment properties in your targets.

Using a feature flag in your code

As mentioned above, Hyphen publishes OpenFeature providers for the most common languages. In this example well will be using the JavaScript Server provider. Provider specific documentation can be found in the left nav.

Installation

Install the provider and the OpenFeature server SDK:

npm install @openfeature/server-sdk @hyphen/openfeature-server-provider

Setup and Initialization

To begin using the Hyphen Provider, follow these steps:

  1. Import the required modules.
  2. Configure the provider with your publicKey and application options.
  3. Register the provider with OpenFeature.
import { OpenFeature } from "@openfeature/server-sdk";
import {
  HyphenProvider,
  type HyphenProviderOptions,
} from "@hyphen/openfeature-server-provider";

const publicKey = "your-public-key-here";

const options: HyphenProviderOptions = {
  application: "your-application-name",
  environment: "production",
};

await OpenFeature.setProviderAndWait(new HyphenProvider(publicKey, options));

Consume a feature flag value

In this example we are providing the context object at read time but a global context object can also be set if your context does not change.

const context: HyphenEvaluationContext = {
  targetingKey: "user-123",
  ipAddress: "203.0.113.42",
  customAttributes: {
    subscriptionLevel: "premium",
    region: "us-east",
  },
  user: {
    id: "user-123",
    email: "[email protected]",
    name: "John Doe",
    customAttributes: {
      role: "admin",
    },
  },
};

const flagDetailsWithContext = await client.getBooleanDetails(
  "feature-flag-key",
  false,
  context
);

console.log(flagDetailsWithContext.value); // true or false