Introduction to FastAPI
Matt Eckerle
Software and Data Leader
@app.delete("/items")
def delete_item(item: Item):
if item.id not in item_ids:
# Return an error
else:
crud.delete_item(item)
return {}
@app.delete("/items")
def delete_item(item: Item):
try:
crud.delete_item(item)
except Exception:
# Return an error
return {}
100
- 599
1
-5
)100
- 199
)200
- 299
)300
- 399
)400
- 499
)500
- 599
)200
- 299
)200 OK
201 Created
202 Accepted
204 No Content
301 Moved Permantently
400 Bad Request
404 Not Found
500 Internal Server Error
from fastapi import FastAPI, HTTPException
app = FastAPI()
@app.delete("/items")
def delete_item(item: Item):
if item.id not in item_ids:
# Send response with status 404 and specific error message
raise HTTPException(status_code=404, detail="Item not found.")
else:
delete_item_in_database(item)
return {}
Introduction to FastAPI