Learn how to use our SDKs

A nice management program is nothing if you can’t embed what you want to manage in it. Therefore we have collected sample SDKs for the most common programming languages in different repositories. We are constantly working on new extensions, if your favorite programming language is not in the list yet, we are sure to provide an SDK for it.

Understanding the use of toggles

Using our Feature Toggle System is as easy as making coffee. With the right ingredients, you can make a coffee that will blow your colleagues away. Let’s take a closer look at the toggle management in the first step. In the simplest case a toggle returns only a boolean value, so it can be true or false. The following configuration would be necessary:

The toggle switcher can now be used to determine whether the toggle should be active, i.e. the who is „true“ or inactive, i.e. the value „false“.So on the client side, comparisons can be easily made. Let’s have a look at a simple Javascript example of the SDK call of the client side:

<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/switchover-js-sdk@latest/dist/switchover.min.js"></script>

</head>

<body>

    <h1>Welcome!</h1>

    <p>Your toggle status: <span id="toggle_status">-</span></p>

    <script>
        var client = Switchover.createClient('ab68ce0c-5d3c-4e97-a702-d79f62f013ff', {
            autoRefresh: false,
            onInit: initialised,
        }, 'debug');
        

        function initialised() {
            console.log("initialised");
            const myElement = document.querySelector('#toggle_status');
            myElement.textContent = client.toggleValue('checkVal', false);
        }
    </script>
</body>

</html>

Let’s take a closer look at the script. In the first step we load the SDK in the head of the document. Via Switchover.createClient we provide the Client ID of the respective environment, you can find it in the respective environment:

For the initialization of the Client SDK there are different parameters which can be different for the used Client SDK. A more detailed description can be found in the SDK specific subpage. The toggle value is then checked via:

myElement.textContent = client.toggleValue('checkVal', false);

The second value in this example when calling the toggleValue method determines the default behavior of the toggle. This is important if, for example, the connection to the toggle management system is not possible. For example, if a teaser should only be displayed when the toggle is set to active, then the default value should be set to „false“.

And that was it, we put our first feature Toggle in the code. But really now guys, for this I need a Feature Toggle Management System? Of course not, it becomes exciting only with conditions!

Conditions

Just below the toggle switch there is a block to define conditions.

This allows more complex data structures and queries to be defined. Currently we do not support user segmentation, but we will provide it in one of the next versions of Switchover. Nevertheless, conditions can still be used to check individual client characteristics and thus respond to individual conditions. For example, if we want to enable a certain function for all Switchover members, we could check the login email address. The same applies to any other feature like IP address or user agent of the client system.

Let’s look at the example with the mail address. All members of Switchover have a mail address in this form : Name@switchover.de. So we create a condition to check for a part of this string, in our case „@switchover.de“:

On the client side we now check in our toggle not only for true/false, but for the condition stored in Switchover. The conditions are validated as JSON which has to be provided as an optional value. In our example we have to change the code to:

var clientmail = "test@switchover.de";
myElement.textContent = client.toggleValue('checkVal',false,{'email' : clientmail});

Any number of conditions can be configured for a feature flag, but our recommendation is not to overdo it and if necessary simply define several flags depending on the goal to be achieved. If multiple conditions are configured on a flag, there is another important setting in the Settings part of the flag.

The Flag Strategy

Switchover currently supports three condition strategies which can be found in the lower part of the toggle configuration:

All: All conditions must be fulfilled

Majority: The majority of the conditions should be fulfilled

At least one: At least one condition must be met