Flagsmith / Flagsmith/flagsmith

OFREP Single flag evaluation (Core API)

Open
#8,435 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

Description

In order to implement the [OFREP specification](https://openfeature.dev/docs/reference/other-technologies/ofrep/openapi), our Core API needs a new endpoint that evaluates a single flag given a set of identity traits. The Edge API counterpart is [Flagsmith/edge-api#712](https://github.com/Flagsmith/edge-api/issues/712).

An interpretation of the specification to our data model is as the following example:

(request)
```http
POST /ofrep/v1/evaluate/flags/{feature.name} HTTP/1.1
Host: {flagsmith_host}
X-API-Key: {server_side_environment_key}
Content-Type: application/json

{
"context": {
"targetingKey": "{identity.identifier}",
"trait1": "value1",
"trait2": "value2"
}
}
```

(response)
```http
HTTP/1.1 200 OK
Content-Type: application/json

{
"key": "{feature.name}",
"value": "{multivariate_feature_option.value}",
"reason": "SPLIT",
"variant": "{multivariate_feature_option.key}"
}
```

(response, unknown flag)
```http
HTTP/1.1 404 Not Found
Content-Type: application/json

{
"key": "{feature.name}",
"errorCode": "FLAG_NOT_FOUND"
}
```

## Acceptance criteria

- Our API exposes a new endpoint `POST /ofrep/v1/evaluate/flags/{flagKey}` compliant to the [OFREP specification](https://openfeature.dev/docs/reference/other-technologies/ofrep/openapi#tag/OFREP-Core/operation/evaluateFlag). As such, the endpoint:
- Serves the flag's value as its remote configuration value, falling back to the flag's enabled state when no value is set.
- Reports the flag's evaluation reason using the vocabulary OFREP defines.
- Responds `404 Not Found` when the environment has no such flag.
- Is billed similarly to other billed endpoints.
- Persists the identity and its traits on the same terms as identity flag evaluation.

Contributor guide

Open the contributing guide

Research direction

Start by locating the existing identity flag evaluation and other billed endpoints in the Core API, then compare their request, persistence, and billing behavior with the OFREP evaluateFlag specification. Verify the new endpoint's value fallback, reason vocabulary, 404 response, identity-trait persistence, and billing behavior against the acceptance criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.