{"id":20485022,"url":"https://github.com/sap-samples/cloud-cf-feature-flags-sample","last_synced_at":"2025-04-13T14:52:56.689Z","repository":{"id":37931233,"uuid":"101639955","full_name":"SAP-samples/cloud-cf-feature-flags-sample","owner":"SAP-samples","description":"A sample application that demonstrates the consumption of Feature Flags service on SAP Cloud Platform, Cloud Foundry environment","archived":false,"fork":false,"pushed_at":"2025-03-10T19:32:09.000Z","size":63,"stargazers_count":16,"open_issues_count":4,"forks_count":7,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-03-27T05:51:11.098Z","etag":null,"topics":["cloud-foundry","feature-flags","feature-toggles","sample","sample-code","sap-cloud-platform","scp"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SAP-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-28T12:16:30.000Z","updated_at":"2025-03-10T19:32:11.000Z","dependencies_parsed_at":"2024-12-20T16:30:50.729Z","dependency_job_id":"4e4cf56a-a060-44bb-aab2-0016dcf2385d","html_url":"https://github.com/SAP-samples/cloud-cf-feature-flags-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fcloud-cf-feature-flags-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fcloud-cf-feature-flags-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fcloud-cf-feature-flags-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fcloud-cf-feature-flags-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SAP-samples","download_url":"https://codeload.github.com/SAP-samples/cloud-cf-feature-flags-sample/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248732509,"owners_count":21152851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-foundry","feature-flags","feature-toggles","sample","sample-code","sap-cloud-platform","scp"],"created_at":"2024-11-15T16:27:05.197Z","updated_at":"2025-04-13T14:52:56.680Z","avatar_url":"https://github.com/SAP-samples.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/cloud-cf-feature-flags-sample)](https://api.reuse.software/info/github.com/SAP-samples/cloud-cf-feature-flags-sample)\n\n# Feature Flags Service Demo Application\n\n## Description\n\nFeature Flags service Demo Application is a simple Spring Boot application that consumes the [Feature Flags service](https://help.sap.com/viewer/2250efa12769480299a1acd282b615cf/Cloud/en-US) on SAP BTP, Cloud Foundry environment. It implements a [feature toggle](https://en.wikipedia.org/wiki/Feature_toggle) (evaluation call to the Feature Flags service) and exposes this feature toggle through a Web user interface. There is also one REST end-point that reads the value of `VCAP_SERVICES` environment variable.\n\n## Requirements\n\n* You have set up [Maven 3.0.x](http://maven.apache.org/install.html).\n* You have an [SAP BTP enterprise (productive) account](https://help.sap.com/docs/btp/sap-business-technology-platform/getting-started-with-enterprise-account-in-cloud-foundry-environment) on Cloud Foundry environment. \n\n  💡**NOTE:** You can also use a [trial account](https://help.sap.com/docs/btp/sap-business-technology-platform/getting-started-with-trial-account-in-cloud-foundry-environment) but some functionalities won't be available for you.\n* You have a space on a Cloud Foundry instance - [productive](https://help.sap.com/docs/btp/sap-business-technology-platform/create-spaces) or [trial](https://help.sap.com/docs/btp/sap-business-technology-platform/cf-env-setting-up-your-trial-account#create-your-trial-space).\n* You have set up the [curl](https://curl.haxx.se/download.html) plug-in for `cmd`.\n* You have installed [cf CLI](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html).\n\n## Running the Application on SAP BTP\n\n💡**NOTE:** This guide uses the **eu20** region (https://emea.cockpit.btp.cloud.sap/cockpit#). \n\n\u003e To use a different SAP BTP region, you need to modify the domain in the requests. See: [Cloud Foundry Regions and API Endpoints](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/350356d1dc314d3199dca15bd2ab9b0e.html)\n\nFollow the steps below to run `Feature Flags Demo Application` on SAP BTP, Cloud Foundry environment.\n\n\u003c!-- toc --\u003e\n\n  * [1. Build the feature-flags-demo Application](#1-build-the-feature-flags-demo-application)\n  * [2. Edit application name in manifest file](#2-edit-application-name-in-manifest-file)\n  * [3. Deploy feature-flags-demo on SAP BTP](#3-deploy-feature-flags-demo-on-sap-btp)\n  * [4. Create a Service Instance of Feature Flags service](#4-create-a-service-instance-of-feature-flags-service)\n    + [4.1 Ensure the feature-flags service exists in the Service Marketplace](#41-ensure-the-feature-flags-service-exists-in-the-service-marketplace)\n    + [4.2 Create a Service Instance of Feature Flags with Plan `standard`](#42-create-a-service-instance-of-feature-flags-with-plan-standard)\n  * [5. Call the feature-flags-demo Application's /vcap_services End-Point](#5-call-the-feature-flags-demo-applications-vcap_services-end-point)\n  * [6. Bind feature-flags-demo to feature-flags-instance](#6-bind-feature-flags-demo-to-feature-flags-instance)\n  * [7. Restage feature-flags-demo](#7-restage-feature-flags-demo)\n  * [8. Ensure that feature-flags-instance is bound to feature-flags-demo](#8-ensure-that-feature-flags-instance-is-bound-to-feature-flags-demo)\n  * [Accessing the Demo Application](#accessing-the-demo-application)\n  * [Accessing the Feature Flags Dashboard](#accessing-the-feature-flags-dashboard)\n  * [9. Evaluate a Missing Feature Flag](#9-evaluate-a-missing-feature-flag)\n  * [10. Create a New Boolean Feature Flag](#10-create-a-new-boolean-feature-flag)\n  * [11. Evaluate the Newly Created Boolean Feature Flag](#11-evaluate-the-newly-created-boolean-feature-flag)\n  * [12. Enable the Boolean Feature Flag](#12-enable-the-boolean-feature-flag)\n  * [13. Verify that the Boolean Feature Flag is Enabled](#13-verify-that-the-boolean-feature-flag-is-enabled)\n  * [14. Create a New String Feature Flag](#14-create-a-new-string-feature-flag)\n  * [15. Evaluate the Newly Created String Feature Flag](#15-evaluate-the-newly-created-string-feature-flag)\n  * [16. Enable the String Feature Flag](#16-enable-the-string-feature-flag)\n  * [17. Verify that the String Feature Flag is Enabled](#17-verify-that-the-string-feature-flag-is-enabled)\n  * [18. Specify Direct Delivery Strategy of a Variation of the String Flag](#18-specify-direct-delivery-strategy-of-a-variation-of-the-string-flag)\n  * [19. Evaluate the String Feature Flag Using Identifier](#19-evaluate-the-string-feature-flag-using-identifier)\n- [Contributing](#contributing)\n- [Code of Conduct](#code-of-conduct)\n- [Licensing](#licensing)\n\n\u003c!-- tocstop --\u003e\n\n### 1. Build the feature-flags-demo Application\n\nRun the following commands, consequently:\n\n    $ git clone git@github.com:SAP/cloud-cf-feature-flags-sample.git\n    $ cd cloud-cf-feature-flags-sample\n    $ mvn clean install\n\n\u003e **Note:** Alternatively, you can use the Eclipse IDE. Choose the `clean install` goal from the _Run As \u003e Maven Build..._ menu.\n\n### 2. Edit application name in manifest file\n\nIt's quite possible that someone else has already deployed the `Feature Flags Demo Application` with the name **feature-flags-demo** (as it is currently set in the `manifest.yml` file). \nCloud Foundry does not allow two applications with the same name to be deployed in the same region! Therefore, we **highly recommend** that you change the application name in the `manifest.yml` file before deploying. For example:\n\n    ---\n    applications:\n    - name: feature-flags-demo123\n      path: target/feature-flags-demo.jar\n\n💡**NOTE:** Use the modified value in all commands that require application name, as well as when requesting the application in a browser or via `curl`.\n\n### 3. Deploy feature-flags-demo on SAP BTP\n\n 1. Log in to your Cloud Foundry landscape. (The `eu20` region is just an example.) Run:\n\n    ```\n    $ cf login -a https://api.cf.eu20.hana.ondemand.com\n    ```\n\n2. Choose your subaccount (org) and space.\n\n3. Deploy the application. Run:\n\n    ```\n    $ cf push\n    ```\n\n### 4. Create a Service Instance of Feature Flags service\n\n#### 4.1 Ensure the feature-flags service exists in the Service Marketplace\n\nRun the following command:   \n  ```\n  $ cf marketplace\n  ```  \nResult:\n\n\n    -----\n    Getting services from marketplace in org \u003cORG_ID\u003e / space \u003cSPACE\u003e as \u003cUSER_ID\u003e...\n    OK\n    service          \tplans    \tdescription\n    ...\n    feature-flags    \tlite, standard     \tFeature Flags service for controlling feature rollout\n    ...\n\n**NOTE:**  If you're using a trial account, the only available service plan will be `lite`.\n\n#### 4.2 Create a Service Instance of Feature Flags\n\n* For a productive account, run:\n  \n    ```\n    $ cf create-service feature-flags standard feature-flags-instance\n    ```\n\n* For a trial account, run:\n\n    ```\n    $ cf create-service feature-flags lite feature-flags-instance\n    ```\n\n\n**Note:** Alternatively, you can use the SAP BTP cockpit. See [Create a Service Instance](https://help.sap.com/docs/feature-flags-service/sap-feature-flags-service/initial-setup#loioc7b30b5bf54149148d2302617917dc3e).\n\n\n### 5. Call the feature-flags-demo Application's /vcap_services End-Point\n\n\u003e **Note**: Expect to receive an empty JSON code - {}.\n\nThe `/vcap_services` end-point simply returns the content of the _VCAP_SERVICES_ environment variable. As for now, there is no service instance bound to `feature-flags-demo`, thus you receive an empty JSON.\n\nIn the command you use the following URL: `\\\u003capplication_URL\\\u003e/vcap_services`. \n\nTo find the value of `\\\u003capplication_URL\\\u003e`, go to the SAP BTP cockpit \u003e **feature-flag-demo** \u003e **Overview** \u003e **Application Routes**.\n\nTo call the application, run (for example):\n\n    $ curl https://feature-flags-demo.cfapps.eu20.hana.ondemand.com/vcap_services\n\n### 6. Bind feature-flags-demo to feature-flags-instance\n\n    $ cf bind-service feature-flags-demo feature-flags-instance\n\n    -----\n    Binding service feature-flags-instance to app feature-flags-demo in org \u003cORG_ID\u003e / space \u003cSPACE\u003e as \u003cUSER_ID\u003e...\n    OK\n    TIP: Use 'cf restage feature-flags-demo' to ensure your env variable changes take effect\n\n\u003e **Note:** Alternatively, you can use the SAP BTP cockpit. See [Bind Your Application to the SAP Feature Flags Service Instance](https://help.sap.com/docs/feature-flags-service/sap-feature-flags-service/initial-setup#loioe7ef0ce6d4b14ae387de5bb18549c250).\n\n### 7. Restage feature-flags-demo\n\nRestage `feature-flags-demo` application so the changes in the application environment take effect.\n\n    $ cf restage feature-flags-demo\n\n### 8. Ensure that feature-flags-instance is bound to feature-flags-demo\n\n\u003e **Note**: Expect to receive the injected environment variables by the Feature Flags service.\n\n    $ curl https://feature-flags-demo.cfapps.eu10.hana.ondemand.com/vcap_services\n\n\nSample JSON response:\n```json\n{\n  \"feature-flags\": [\n    {\n      \"credentials\": {\n        \"x509\": {\n          \"certificate\": \"...\",\n          \"key\": \"...\",\n          \"clientid\": \"...\",\n          \"...\": \"...\"\n        },\n        \"password\": \"aa_12345678XYZZZZZ000mnopRE+qs0e=\",\n        \"uri\": \"https://feature-flags.cfapps.eu20.hana.ondemand.com\",\n        \"username\": \"sbss_x234osj//pmabsuskr6nshmb2arw6dld4hfb3cj4m2bonkqmm3ts6c68mdpzxz2fma=\"\n      },\n      \"syslog_drain_url\": null,\n      \"volume_mounts\": [ ],\n      \"label\": \"feature-flags\",\n      \"provider\": null,\n      \"plan\": \"standard\",\n      \"name\": \"feature-flags-instance\",\n      \"tags\": [\n        \"feature-flags\"\n      ]\n    }\n  ]\n}\n```\n\n### Accessing the Demo Application\n\nThe web interface of the demo application will be accessed multiple times throughout this tutorial. Here is how to open it: \n\n1. Go to the SAP BTP cockpit.\n2. Navigate to the `feature-flags-demo` application overview.\n3. Open the link from the **Application Routes** section. For example: `https://feature-flags-demo-happy-bear.cfapps.eu20.hana.ondemand.com`\n4. The **Evaluation Form** opens.\n\n### Accessing the Feature Flags Dashboard\n\nThe `Feature Flags Dashboard` will be accessed multiple times throughout this tutorial. Here is how to open it: \n\n1. Go to the SAP BTP cockpit.\n2. Navigate to your subaccount.\n3. Create a subscription to **Feature Flags Dashboard**. To do that, create an instance of the Feature Flags service, with plan `dashboard`.\n4. Access **Feature Flags Dashboard** from the list of subscribed applications.\n5. Select the service instance you are currently working with.\n\n💡**NOTE:** The dashboard URL always has the following pattern: \n\n`https://\u003csubdomain\\\u003e.feature-flags-dashboard.cfapps.eu20.hana.ondemand.com/manageinstances/\u003cinstance-id\\\u003e`\n\n\u003e The \u003cinstance-id\u003e is a unique ID of your Feature Flag service instance.\n\n### 9. Evaluate a Missing Feature Flag\n\n\u003e **Note**: Expect the feature flag to be missing.\n\n1. Open the demo application as described [here](#accessing-the-demo-application).\n2. Enter a feature flag with a random name, for example `my-boolean-flag`.\n3. Choose **Evaluate**.\n4. The result should state that a feature flag with this name is missing.\n\n### 10. Create a New Boolean Feature Flag\n\n1. Open the `Feature Flags Dashboard` as described [here](#accessing-the-feature-flags-dashboard).\n2. Choose **New Flag**.\n3. Fill in the required fields. For example:\n   * **Name**:  `my-boolean-flag`\n   * **Description**: `Super cool feature`\n   * **State**: `OFF`\n5. Choose **Save**.\n\n### 11. Evaluate the Newly Created Boolean Feature Flag\n\n\u003e **Note**: Expect the variation to be `false`.\n\n1. Open the demo application as described [here](#accessing-the-demo-application).\n2. Enter the Boolean feature flag name.\n3. Choose **Evaluate**.\n4. The result should state that the feature flag is of type `BOOLEAN` and its variation is `false`.\n\n### 12. Enable the Boolean Feature Flag\n\n1. Open the `Feature Flags Dashboard` as described [here](#accessing-the-feature-flags-dashboard).\n2. Enable the Boolean feature flag using the switch in the **Active** column.\n\n### 13. Verify that the Boolean Feature Flag is Enabled\n\n\u003e **Note**: Expect the variation to be `true`.\n\n1. Open the demo application as described [here](#accessing-the-demo-application).\n2. Enter the Boolean feature flag name.\n3. Choose **Evaluate**.\n4. The result should state that the feature flag is of type `BOOLEAN` and its variation is `true`.\n\n\u003e ### CAUTION!\n\u003e The next procedures (14 - 19) are only applicable for productive accounts, which means plan `standard`.\n\n### 14. Create a New String Feature Flag\n\n1. Open the `Feature Flags Dashboard` as described [here](#accessing-the-feature-flags-dashboard).\n2. Choose **New Flag**.\n3. Fill in the required fields. For example:\n    * **Name**: `my-string-flag`\n    * **Description**: `Coolest of features`\n    * **Type**: `String`\n    * **State**: `OFF`\n4. Enter the following values as different variations of the flag:\n    * **Var. 1**: `variation-when-inactive`\n    * **Var. 2**: `variation-when-active`\n    * **Var. 3** (choose the **Add** button with the '+' sign to add a new field): `variation-for-friends-and-family`\n5. From the **Default Variation**, open the **Deliver** combo box and select `Var. 2`.\n6. Choose **Save**.\n\n### 15. Evaluate the Newly Created String Feature Flag\n\n\u003e **Note**: Expect the variation to be `variation-when-inactive`.\n\n1. Open the demo application as described [here](#accessing-the-demo-application).\n2. Enter the string feature flag name.\n3. Choose **Evaluate**.\n4. The result should state that the feature flag is of type `STRING` and its variation is `variation-when-inactive`.\n\n### 16. Enable the String Feature Flag\n\n1. Open the `Feature Flags Dashboard` as described [here](#accessing-the-feature-flags-dashboard).\n2. Enable the string feature flag using the switch in the **Active** column.\n\n### 17. Verify that the String Feature Flag is Enabled\n\n\u003e **Note**: Expect the variation to be `variation-when-active`.\n\n1. Open the demo application as described [here](#accessing-the-demo-application).\n2. Enter the string feature flag name.\n3. Choose **Evaluate**.\n4. The result should state that the feature flag is of type `STRING` and its variation is `variation-when-active`.\n\n### 18. Specify Direct Delivery Strategy of a Variation of the String Flag\n\n1. Open the `Feature Flags Dashboard` as described [here](#accessing-the-feature-flags-dashboard).\n2. Select the string feature flag.\n3. Choose the **Edit Flag** button.\n4. Go to the **Strategy** section, subsection **Direct Delivery**, and choose the '+' button.\n5. Select **Var. 3** from the combobox and enter `friends-and-family` in the text input.\n6. Choose **Save**.\n\n### 19. Evaluate the String Feature Flag Using Identifier\n\n\u003e **Note**: Expect the variation to be `variation-for-friends-and-family`.\n\n1. Open the demo application as described [here](#accessing-the-demo-application).\n2. Enter the string feature flag name.\n3. For the **Identifier (optional)** field, enter `friends-and-family`.\n4. Choose **Evaluate**.\n5. The result should state that the feature flag is of type `STRING` and its variation is `variation-for-friends-and-family`.\n\n\u003e Once **Direct Delivery** is configured, the Feature Flags service requires providing an identifier. If such is not present, an error is thrown.\n\n💡**NOTE:** `variation-when-active` is returned for all identifiers - except for those explicitly configured in the `Feature Flags Dashboard` for which the provided rules apply (like the `friends-and-family` identifier).\n\n## Contributing\n\nRefer to the [contrubuting guideline](/CONTRIBUTING.md).\n\n## Code of Conduct\nRefer to the [SAP Open Source Code of Conduct](https://github.com/SAP-samples/.github/blob/main/CODE_OF_CONDUCT.md).\n\n## Licensing\nSee [LICENSE](/LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap-samples%2Fcloud-cf-feature-flags-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsap-samples%2Fcloud-cf-feature-flags-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap-samples%2Fcloud-cf-feature-flags-sample/lists"}