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.Cursorobject has arowcountattribute that will be greater than or equal to 1 if the ID existed.Alternately, since
DELETEis 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).