Skip to content
Discussion options

You must be logged in to vote

For example:

from fastapi import FastAPI, Query

app = FastAPI()


@app.get("/test/{user_id}")
def test(user_id: str, query_user_id: str = Query(..., alias="user_id")):
    return {"user_id": user_id, "query_user_id": query_user_id}

It works, validates the path and query parameters, generates the OpenAPI schema, etc.

Swagger UI has a bit of trouble showing it correctly, but if you go to the URL directly: http://127.0.0.1:8000/test/foo?user_id=bar

You get the response:

{"user_id":"foo","query_user_id":"bar"}

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
5 participants
Converted from issue

This discussion was converted from issue #131 on February 28, 2023 14:59.