Evaluate flags
The POST/flags endpoint allows you to send a context object serialized as JSON and retrieve all 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 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 exists 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
has a value ofnull
.flagB
is archived, deleted, or maybe it just does not exist. (It is simply not part of the response)flagC
has a value of"foo"
flagD
has a value offalse
You should never rely on whether or not a key is part of the response in your code. Always read the value of the flag with a hard coded default value if the key does not exist.
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 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.