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 - 5991 -5)100 - 199)200 - 299)300 - 399)400 - 499)500 - 599)200 - 299)200 OK201 Created202 Accepted204 No Content301 Moved Permantently400 Bad Request404 Not Found500 Internal Server Errorfrom 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