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:
- Navigate to your Hyphen Dashboard.
- Select your Project from the list.
- Go to the Access tab.
- Copy the Public Key for your project.
All public keys start with public_
to make them easy to identify.
Creating a Toggle
- From the Project Details page, navigate to Toggles, then Create a Toggle button.
- Select a toggle type, provide a key (for SDK references), and set a logical default value.
- While optional, adding a clear description helps team members understand the toggle’s purpose.
- Click Create to save the toggle, which redirects you to the toggle detail page.
This page contains Telemetry information and also you to configure targets.
Targeting
- On the toggle detail page scroll down to the
Targets
sections can clickAdd a Target
. - In the drawer you can choose one more more target criteria, values from the context, to evaluate on and then provide that resulting value.
Toggle will likely have many targets and evaluation starts at the top, first target, and works it's way down to the bottom, last target, and exits as soon as a target matches. When that happens the targets value will be returned for the evaluation. Targets may be reordered in the application.
It is recommended to use the context's application and environment properties in your targets.
Using the toggle 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:
- Import the required modules.
- Configure the provider with your
publicKey
and application options. - 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 toggle 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
Updated 11 days ago