I had an issue with that I cann't use my Post request in FastAPI , I used the Post request but the terminal displayed the Get request and I don't know why. And when I used the Body(...) to declare the dict type but it looked didn't work
from fastapi.params import Body
from pydantic import BaseModel
app = FastAPI()
# payload : input parameter of the function
# dict: type of data
# được truyền vào bằng cách sử dụng FastAPI's Body dependency. ... được sử dụng để chỉ định rằng tham số
# này là bắt buộc và không thể bỏ qua.
@app.post("/create")
def create_posts(payload: dict = Body(...)):
# It will extract all the field from the body to the dict
print(payload)
return {"message": f"successfully created posts: {payload['title']}"}
@app.get("/")
def get_data():
return {"message": "Hello World"}
Here is my error
INFO: Will watch for changes in these directories: ['T:\\FastAPI']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [14464] using WatchFiles
INFO: Started server process [3468]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: 127.0.0.1:60812 - "GET /create HTTP/1.1" 405 Method Not Allowed
INFO: 127.0.0.1:60812 - "GET /cart.json HTTP/1.1" 404 Not Found
INFO: 127.0.0.1:60812 - "GET /create HTTP/1.1" 405 Method Not Allowed```