tiangolo / fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production
https://fastapi.tiangolo.com/
MIT License
73.34k stars 6.18k forks source link

♻️ Return status_code 409 when item already exists #11504

Open hongjiaherng opened 2 months ago

hongjiaherng commented 2 months ago

Typo in docs:

Correct references:

Code snapshot:

@app.post("/items/", response_model=Item)
async def create_item(item: Item, x_token: Annotated[str, Header()]):
    if x_token != fake_secret_token:
        raise HTTPException(status_code=400, detail="Invalid X-Token header")
    if item.id in fake_db:
        raise HTTPException(status_code=400, detail="Item already exists") # NOTE: This should return 409 instead
    fake_db[item.id] = item
    return item
tiangolo commented 2 months ago

📝 Docs preview for commit c9d15a29f00b3b9ba01a6b060e361c9498673d75 at: https://4cf3287f.fastapitiangolo.pages.dev

tiangolo commented 2 months ago

📝 Docs preview for commit b2a88e3d4d4687cb802afefe2c3db268c54f5cbf at: https://f7b2513e.fastapitiangolo.pages.dev