[FEATURE] Query string flags
See original GitHub issueIs your feature request related to a problem? Please describe.
It is valid in HTML to have a query string parameter which has no value. For example: ?my-flag
.
I usually think of this as a shorthand for writing ?my-flag=true
.
FastAPI ignores these.
Describe the solution you’d like
FastAPI should not ignore these flags.
It could set their value to be:
True
.- Empty string
''
(I think this is bad idea - in intent these are usually for turning features on/off). - Some constant like
FastAPI.params.EmptyFlag
.
Alternatively, you could make some special type which marks a query string parameter as present or not.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Feature Flags in JavaScript - Pete Hodgson
#Feature flagging using query strings, javascript and css As mentioned above, I'll be describing a simple but effective feature flagging ...
Read more >Control functionality with feature flags - Retool Docs
The Feature Flags component contains a list of toggles that can trigger queries when enabled or disabled. Each toggle can include a description...
Read more >Feature Flag Best Practices: When and How to Use Them
When do you use feature flags? What kinds of flags are there? Learn the answers to these questions and more in this blog...
Read more >Query string - Wikipedia
A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters. A query string commonly includes...
Read more >Simple query string query | Elasticsearch Guide [8.5] | Elastic
You can use the flags parameter to limit the supported operators for the simple query string syntax. To explicitly enable only specific operators, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the good advice. I will bear that in mind next time I make something with FastAPI.
Here’s the thing, what is now supported in Starlette is to have empty query param flags. So, they are in the
request.query_params
dict, but with a value ofNone
, because actually nothing was provided.So, you could extract them if you use the request directly and check if the query parameter exists and if it is None: https://fastapi.tiangolo.com/advanced/using-request-directly/
But it wouldn’t make sense to make them used by default and take them as
True
implicitly, as that would be inconsistent with all the other cases.For example, all these would make
q
have a value
False`:http://example.com?q=false
http://example.com?q=0
http://example.com?q=""
http://example.com?q=
But if then suddenly this made
q
to have a valueTrue
:http://example.com?q
That would probably be quite unexpected.
So, yes, you can implement it by using the request directly, but it wouldn’t make sense as a default in FastAPI.