Get flags config

The GET/config endpoint allows you to retrieve all active flag's configurations at once, making it possible to then evaluate an extremely high number of flags locally without doing any API calls.

Getting the configuration

curl 'https://api.tggl.io/config' \
  -H 'x-tggl-api-key: <server api key>'

The response is a JSON array containing all active flags:

[
  {
    "slug": "flagA",
    "conditions": [
      {
        "rules": [
          {
            "key": "userId",
            "operator": "STR_EQUAL",
            "negate": false,
            "values": [
              "u1",
              "u2"
            ]
          }
        ],
        "variation": {
          "active": true,
          "value": "foo"
        }
      }
    ],
    "defaultVariation": {
      "active": false,
      "value": null
    }
  },
  {
    "slug": "flagB",
    "conditions": [],
    "defaultVariation": {
      "active": true,
      "value": "bar"
    }
  }
]

Each element of the array is a Flag object as defined in tggl-core, with an additional slug key.

Evaluating flags

Once the configuration is retrieved, you should be able to evaluate flags locally without doing any API calls. You can refer to the reference TypeScript implementation in tggl-core.

To test that your implementation is correct, you can copy the standard_tests.json file in your project. It contains an array of tests:

[
  {
    "name": "no conditions, inactive default variation",
    "flag": {
      "conditions": [],
      "defaultVariation": {
        "active": false,
        "value": "foo"
      }
    },
    "context": {},
    "expected": {
      "active": false,
      "value": null
    }
  },
  // ...
]

Each test has 4 keys:

  • name: the name of the test
  • flag: the flag to evaluate as the API would return it
  • context: the context to evaluate the flag against
  • expected: the expected result of the evaluation

You can then run the tests against your implementation in an automated way. See TypeScript or PHP examples.