flagr
flagr copied to clipboard
[Feature Request] GetFlagByKey (or similar) endpoint
Expected Behavior
There should be an endpoint, and corresponding functions in the various client libraries, that allows you to get a flag based on its unique key.
Current Behavior
Currently, as far as I know, the only way to 'get' a single flag is by its numeric ID. The only other alternative is to use the FindFlags function, which has a lot more overhead (FindFlagsOpts, pulling the first entry, checking yourself that there aren't more than one)
Possible Solution
New func that either:
- More or less reimplements GetFlag but for a string on the key instead of the ID
- Calls FindFlags and returns the singular result or returns an error if no results
- This solution would require more processing since FindFlags uses
like
so we may get multiple results where 0 or many of them match the query string
- This solution would require more processing since FindFlags uses
Context
Want a more concise way (in terms of lines of code) to find a flag based on its key.
Basically would turn
ffo := goflagr.FindFlagsOpts{
Key: optional.NewString("flagr/test-flag"),
Preload: optional.NewBool(true),
}
flags, _, _ := apiClient.FlagApi.FindFlags(nil, &ffo)
myFlag = flags[0]
Into
myFlag = apiClient.FlagApi.GetFlagByKey(nil, "flagr/test-flag")
Willing to take this on myself, but curious about your thoughts on approach @zhouzhuojie
Thinking of the API design, there are many options (see below), and /
in the flagKey can cause some confusion in the URL, wondering if URL encoded string is needed here.
GET /api/v1/flag_keys/<key>
GET /api/v1/flag_by_key/<key>
GET /api/v1/flags?key=<key>
The other option is to keep the api, but add your own utility function and consolidate several lines of FindFlags into a single function. flagKey is already indexed, so I think the performance is not a problem.
and / in the flagKey can cause some confusion in the URL
I agree. It'll either need to be properly URL encoded or we could make this particular GET endpoint accept a JSON body with the string as part of that body
add your own utility function
I'm not opposed to this idea necessarily, but it does require more processing overhead on both the client side and server side to do so - as the server has to get more items from the DB than it needs and then the client has to filter through them
add your own utility function
I'm not opposed to this idea necessarily, but it does require more processing overhead on both the client side and server side to do so - as the server has to get more items from the DB than it needs and then the client has to filter through them
Do you have high volume of traffic that needs to use GET flag by key? Usually, this endpoint is used by admins to look at the dashboard. The high volume of traffic should directly go to the evaluation endpoints.
Stale issue message