Example

Featureflags Unleash

Demonstrates how to evaluate Unleash feature flags through the Helix feature-flag client. Shows the Unleash starter autoconfiguration, FeatureClient, FeatureContext, and the Helix properties used to point the SDK at an Unleash server.
Group
REST API
Path
examples/rest-api/featureflags-unleash

Overview

Helix Spring Boot web service that shows how to evaluate feature flags with the Helix Unleash 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-unleash --init-script "$(pwd)/helix.init.gradle"

What It Shows

  • adding helix-featureflags-unleash-spring-boot-starter to a Helix REST API
  • evaluating Unleash flags through the Helix FeatureClient
  • building a FeatureContext with user and plan attributes for targeting
  • configuring the Unleash URL, instance id, and environment through Helix application properties
  • relying on the starter to create the Unleash client and Helix feature client wiring

Endpoints

  • GET /v1/featureflags-unleash/experience/{userId}
  • GET /liveness
  • GET /health

Example success response

{
  "userId": "pilot-user",
  "plan": "standard",
  "betaCheckoutEnabled": true,
  "prioritySupportEnabled": false,
  "message": "Serve the beta checkout flow.",
  "evaluationMode": "unleash-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

Start the example with a local Unleash stack:

This will:

  • start PostgreSQL and Unleash through the localstack-backed local runtime - wait for Unleash to be healthy - seed Unleash with the demo context field, flags, and strategies - start the Spring Boot service on port 18080

The local Unleash UI is available at http://localhost:4242 with:

  • username: admin - password: unleash4all

If you only want the local Unleash stack without starting the app:

If you want to re-apply the demo flags and strategies against a running local Unleash instance:

The local seed sets up:

  • pilot-user gets beta-checkout - any user on the enterprise plan gets both flags - standard-user on the standard plan gets neither flag

The example points the Unleash client at the development environment by default so it matches the local Unleash environment.

This local Unleash setup is intentionally insecure and meant only for local development. It uses well-known local admin credentials and a fixed local client token so the example can run without extra setup.

The tests for this example override the unleash-feature-client bean so the application code can be verified without depending on a live Unleash environment.

Then try:

You can stop and remove the local Unleash stack with:

Command

Trying the API


./gradlew bootRunLocal

Command

Trying the API


./gradlew unleashUp

Command

Trying the API


./gradlew seedLocalUnleash

Command

Trying the API


curl "http://localhost:18080/v1/featureflags-unleash/experience/pilot-user?plan=standard"

curl "http://localhost:18080/v1/featureflags-unleash/experience/standard-user?plan=enterprise"

curl "http://localhost:18080/v1/featureflags-unleash/experience/standard-user?plan=standard"

Command

Trying the API


./gradlew unleashDown