Thank you very much for developing and maintaining FastAPI, it's great 🙂
Is your feature request related to a problem
I tried to create a POST route with username: str and password: str parameters in the function signature. I was expecting FastAPI to search for username and password in the request body (since I used @app.post), but instead it gets them from the URL, as query parameters. It seems it only works when the parameter is a Pydantic model, not a builtin type.
The solution you would like
With
@app.post("/route/")
def my_route(username: str, password: str):
...
Accept username and password as fields of the request body, not as query parameters.
Describe alternatives you've considered
Use Pydantic models. It works fine, it's just a bit less straight-forward.
class LoginForm(BaseModel):
username: str
password: str
@app.post("/route/")
def my_route(login_data: LoginForm):
...
It could also be emphasized in the docs (https://fastapi.tiangolo.com/tutorial/body/) that it will not work with built-in types, only with Pydantic models.
Additional context
I'm not sure my feature request makes sense: generally speaking, if POST requests can also use query parameters in the URL, then it's impossible to distinguish the ones that should be in the request body and the ones that appear in the URL as query parameters. It means it would not be possible to build the openapi.json I guess. In that case, please close this as invalid 🙂
Thank you very much for developing and maintaining FastAPI, it's great 🙂
Is your feature request related to a problem
I tried to create a POST route with
username: strandpassword: strparameters in the function signature. I was expecting FastAPI to search forusernameandpasswordin the request body (since I used@app.post), but instead it gets them from the URL, as query parameters. It seems it only works when the parameter is a Pydantic model, not a builtin type.The solution you would like
With
Accept
usernameandpasswordas fields of the request body, not as query parameters.Describe alternatives you've considered
Use Pydantic models. It works fine, it's just a bit less straight-forward.
It could also be emphasized in the docs (https://fastapi.tiangolo.com/tutorial/body/) that it will not work with built-in types, only with Pydantic models.
Additional context
I'm not sure my feature request makes sense: generally speaking, if POST requests can also use query parameters in the URL, then it's impossible to distinguish the ones that should be in the request body and the ones that appear in the URL as query parameters. It means it would not be possible to build the openapi.json I guess. In that case, please close this as invalid 🙂