Replies: 3 comments
-
@pawamoy So your example will look something like this: from fastapi import FastAPI, Body
app = FastAPI()
@app.post("/route/")
def my_route(username: str = Body(...), password: str = Body(...)) -> None:
print("username:", username)
print("password length:", len(password)) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Indeed! Thank you for pointing me to this page. This feature request can definitely be closed. I'm really sorry for the noise! Cheers |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks @nsidnev for your help here! 🤓 🍰 Thanks @pawamoy for reporting back and closing the issue 🌮 🚀 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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
andpassword: str
parameters in the function signature. I was expecting FastAPI to search forusername
andpassword
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
Accept
username
andpassword
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.
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 🙂
Beta Was this translation helpful? Give feedback.
All reactions