Skip to content

C++ client SDK for Unleash, an open-source feature flag management service.

License

Notifications You must be signed in to change notification settings

aruizs/unleash-client-cpp

Repository files navigation

Unleash Client SDK for C++

Build Status Build Status Build Status codecov Maintainability Rating Reliability Rating Security Rating

This repository provides a C++ client SDK for Unleash that meets the Unleash Client Specifications.

Features

The below table shows what features the SDKs support or plan to support.

  • Feature toggles
  • Built-in strategies
  • Unleash context
  • Strategy constrains
  • Application registration
  • Variants
  • Custom stickiness (WIP)
  • Bootstraping
  • Usage Metrics

Requirements

  • Compatible C++17 compiler such as Clang or GCC. The minimum required versions are Clang 4 and g++7.

Usage

Include Unleash library

#include <unleash/unleashclient.h>

Initialization

The unleashClient can be initialized with the following parameters but only appName and unleashServerUrl are mandatories.

Config Required? Type Default value
Unleash URL Yes String N/A
App. Name Yes String N/A
Instance ID. No String N/A
Environment No String N/A
Authentication No String N/A
Refresh Interval (ms) No Int 15000
Registration No Bool False
unleash::UnleashClient unleashClient = unleash::UnleashClient::create("appName", "unleashServerUrl").instanceId("intanceId").environment("environment").authentication("token").refreshInterval(pollingTime).registration(boolValue);
unleashClient.initializeClient();

Feature Flag is enabled?

  • Simple toggle:
unleashClient.isEnabled("feature.toogle");
  • Toggle with context:
    #include "unleash/context.h"
    ...
    unleash::Context context{"userId", "sessionId", "remoteAddress"}
    unleashClient.isEnabled("feature.toogle", context);

Getting a Variant

    #include "unleash/context.h"
    ...
    unleash::Context context{"userId"};
    auto variant = unleashClient.variant("feature.toogle", context);
    ...
    /*
    The variant response is an instance of the following structure:
    {
      std::string name;
      unsigned int weight;
      bool enabled;
      bool featureEnabled;
      std::string payload;
    }
    */

For more information about variants, see the Variant documentation.

Integration

Building with CMake

The following requirements need to be installed to build the library using CMake:

  • CMake 3.19+
  • Conan 2 (CMakeDeps Generator)

By default, it provides the static library. The shared version shall be available using the CMake option BUILD_SHARED_LIB=YES.

The installation files include the UnleashConfig.cmake to integrate this library using the target unleash::unleash.

To build unleash client with conan and CMake run the following commands:

conan install . --output-folder=build --build=missing --settings=build_type=Debug
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=$(pwd)/build
cmake --build build

Substitute Debug for Release to build the release version. The CMAKE_PREFIX_PATH and --output-folder parameters should point to the same directory, make sure to use an absolute path for the CMAKE_PREFIX_PATH.

Conan

This package is published in Conan Center as unleash-client-cpp/1.1.1.

Tested services

  • Gitlab using application name and instance id parameters for authentication.
  • Self-hosted unleash using client token for authentication.

Used third-party tools

Thanks a lot to the following tools for your contribution:

About

C++ client SDK for Unleash, an open-source feature flag management service.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •