I'm writing an API in Flask, and my HTTP DELETE method deletes a record in SQLite according to its ID passed as a JSON.
Assuming the ID passed does not exist, no error is thrown and success 200 is returned. Is that the expected behaviour? Should I throw an HTTP error? If so, how can I check if db.execute() query did not finish properly?
Sorry but this is my first time writing an API in Flask and I'm still learning it. Thanks
The sqlite3.Cursor object has a rowcount attribute that will be greater than or equal to 1 if the ID existed.
Alternately, since DELETE is idempotent you could assume that every ID you are provided was valid at some point and always return a 200 or 204 (although a 404 is better if the resource never could have existed).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With