Get flags config

The GET/config endpoint allows you to retrieve all 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 flags. All inactive or archived flags are not present in the response.

Example
Schema
YAML
JSON
TypeScript
[
  {
    "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 594 tests that you can run against your implementation. The included tests look like this:

[
  {
    "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.

Error handling

If you API key is invalid or missing, you will receive a 401 Unauthorized response.

401 Unauthorized
{
  "error": "Invalid API key"
}