send JSON
Return a dictionary and Flask sends it as JSON, for other programs to read.
@app.route("/api/members")
def api_members():
return {"members": members}Web apps with Flask · In any playground, open Reference to copy these.
Return a dictionary and Flask sends it as JSON, for other programs to read.
@app.route("/api/members")
def api_members():
return {"members": members}The type after each parameter (int, str, float) is checked: a wrong value gets an error reply (422) before your code runs.
@api.get("/year")
def year(y: int):
return {"next": y + 1}