Boolean return value should result in JSON response
septatrix opened this issue · 1 comments
septatrix commented
Currently only dicts and lists are converted to JSON responses. However, it is also quite common for APIs to return a boolean scalar. For now this will result in an exception and if one wants to do this, they have to use jsonify
.
I think allowing boolean return value to be converted into JSON responses is therefore a nice QoL improvement. And because it is currently prohibited, there is no backwards incompatible change.
@app.get("/test-registration-state")
def registration_state():
return quart.json.jsonify(some_check()) # old
return some_check() # new
davidism commented
I don't want to add shortcuts for the primitive types. Return a JSON object or list of objects is common in APIs. But automatically handling bools and ints seems easy to hide programming errors unintentionally. It's easy enough to either return jsonify(True)
or {"done": True}
instead.