← Teacher guide Markdown for Prepare

APIs: cheat sheet

Web apps with Flask · In any playground, open Reference to copy these.

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}

a FastAPI route

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}