valgur / unleash-client-cpp

C++ client SDK for Unleash.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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
  • Usage Metrics
  • Variants
  • Custom stickiness

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
unleash::UnleashClient unleashClient = unleash::UnleashClient::create("appName", "unleashServerUrl").instanceId("intanceId").environment("environment").authentication("token).refreshInterval("pollingTime");
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);

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.

License:MIT License


Languages

Language:C++ 84.2%Language:CMake 15.8%