Evaluate flags
The POST/flags endpoint allows you to send a context object serialized as JSON and retrieve all active flags at once for that context.
Evaluating a single context
The context object is a JSON object that can contain any key/value pairs you want.
The response is a JSON object listing all active flags and their corresponding values for that context:
Since the value of a flag can be falsy, you must check if a key exists to determine if a flag is active or not. Checking the value may lead to false negatives.
Interpreting the response
Most of the time, checking if a key exists is enough, but if you want to do anything more complex than on / off, you might need to read the flag's value.
The above response can be interpreted as follows:
flagA
is active, and its value isnull
.flagB
is inactive, deleted, or maybe it just does not exist. (It is simply not part of the response)flagC
is active, and its value is"foo"
flagD
is active, and its value isfalse
It might be tempting to think that values of null
or false
means that the flag is inactive, but it is not.
Inactive flags are just not in the response, there might be a few reasons for that:
- The flag does not exist, it was never created
- The flag exists but is archived
- The flag exists but it is inactive (the main switch is off on the app)
- The flag exists, it is active, but for that particular context the conditions make it fall into the inactive variation
Evaluating flags in batches
On the backend you might need to evaluate a lot of contexts at once. Doing multiple HTTP requests will kill performance, you can instead pass an array of contexts in a single API call and get back an array of responses.
Contexts objects do not have to share the same keys. The response is an array of the same length:
You can interpret the response the same way as before. Each response object corresponds to the context object at the same index.
Typed responses
For languages that are strongly typed, you can use the POST/typed-flags endpoint to retrieve the list of all active flags for a list of contexts, with theire associated types.
Unlike the /flags
endpoint, /typed-flags
only accepts an array of contexts, to evaluate only a single context, pass an array of length 1.
Error handling
If you API key is invalid or missing, you will receive a 401 Unauthorized response.
If the request body is invalid, you will receive a 400 Bad Request response.