-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request.query values as is not list data type #73
Comments
Hi @sugizo, I finally opted for the current behavior because I thought it would be the "lesser evil":
The recommended way to read query parameters is to use the Would you take into consideration to use a JSON request payload instead of query string? This way, you might achieve what you desire this way: from blacksheep.server.bindings import FromJson
@app.route('/api/post/{tablename}', methods = ['POST'] )
def post(tablename, values: FromJson[dict]):
# TODO: validate values
row = db[tablename].validate_and_insert(**values)
db.commit()
return response.json(row.as_dict()) I could add an API to read the query as a flat |
solution you provide consider it documented on here
taken on same link above so, the code provided on first issue is cutted down to make it focus on request.query, here is the full code for insert new data
so can insert new data via cli either using any of these command
question thanks |
For such scenario, currently you need something like your Notes:
def dict_values(raw_ori):
return {k: v[-1] for k, v in raw_ori.items()}
from urllib.parse import parse_qs
parse_qs("a=20&b=10")
# {"a": ["20"], "b": ["10"]}
I hope this helps. I will take consider implementing something like Flask does on this matter, to improve UX when handling queries with single values. |
yes aware of that, thx or perhaps you have any idea to simplified dict_values() with if condition and for loop are welcome thanks |
Is your feature request related to a problem?
background
insert or update database from cli must convert first
e.g.
request.query
curl -X POST -i "http://localhost:8000/api/post/instrument?name=name3&strings=3"
result without calling dict_values() function, the value data type list, will return an error when insert or update database
expected result, solve by calling dict_values() function
Describe the solution you'd like
insert or update database from cli as is data (values not list data type) from request.query
e.g.
Additional context
question
is it possible to have request.query values as is not list data type ?
so that can insert or update database without calling dict_values() function
thanks
The text was updated successfully, but these errors were encountered: