question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE] Query string flags

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
GlennScommented, Apr 14, 2020

Thanks for the good advice. I will bear that in mind next time I make something with FastAPI.

1reaction
tiangolocommented, Apr 12, 2020

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 of None, 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 value True:

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found