Overview
Helix Spring Boot web service that shows how to evaluate feature flags with the Helix LaunchDarkly starter.
Run this example from the shared examples build:
Run
Run this example from the shared examples build
./gradlew -p examples runExample -Pexample=rest-api/featureflags-launchdarkly --init-script "$(pwd)/helix.init.gradle"
What It Shows
- adding
helix-featureflags-launchdarkly-spring-boot-starterto a Helix REST API - evaluating LaunchDarkly flags through the Helix
FeatureClient - building a
FeatureContextwith user and plan attributes for targeting - configuring the LaunchDarkly SDK key through Helix application properties
- relying on the starter to create the LaunchDarkly client and Helix feature client wiring
Endpoints
GET /v1/featureflags-launchdarkly/experience/{userId}GET /livenessGET /health
Example success response
{
"userId": "pilot-user",
"plan": "standard",
"betaCheckoutEnabled": true,
"prioritySupportEnabled": false,
"message": "Serve the beta checkout flow.",
"evaluationMode": "launchdarkly-sdk"
}
Development
Building the Application
Run the following command to build the service:
Command
Building the Application
./gradlew clean build
Testing the Application
Run the following command to run the service tests:
Command
Testing the Application
./gradlew test
./gradlew integration
Trying the API
Run the service with a LaunchDarkly SDK key:
Then try:
This example assumes you have corresponding LaunchDarkly flags defined in your environment, such as:
beta-checkout-priority-support
The tests for this example override the launchdarkly-feature-client bean so the application code can be verified without depending on a live LaunchDarkly environment.
Command
Trying the API
./gradlew bootRun --args='--helix.featureflags.launchdarkly.sdkkey=YOUR_SDK_KEY'
Command
Trying the API
curl "http://localhost:8080/v1/featureflags-launchdarkly/experience/pilot-user?plan=standard"
curl "http://localhost:8080/v1/featureflags-launchdarkly/experience/standard-user?plan=enterprise"
curl "http://localhost:8080/v1/featureflags-launchdarkly/experience/standard-user?plan=standard"