DELETE: Remove the Game
Learn how to delete a game through REST API’s DELETE method.
We'll cover the following...
Using the DELETE
method
The final method, the deletion command, simply calls the session’s DELETE
method.
Press + to interact
def delete(self, game_id):'''Delete record for game ``game_id``:route: ``/<game_id>`` DELETE:returns:An acknowledgment object:* ``message`` Either 'One' or 'Zero' records deletedThis method removed the game from its table'''game = g.games_db.query(Game).filter(Game.game_id == game_id).one_or_none()if game is not None:g.games_db.delete(game)g.games_db.commit()msg = 'One record deleted'else:msg = 'Zero records deleted'return {'message': msg}
Idempotency
Recall that the DELETE
method should be idempotent. Therefore, applying the method twice should have the same impact as applying it once. ...