Search⌘ K
AI Features

DELETE: Remove the Game

Understand how to apply the DELETE HTTP method to safely remove game records in a REST API. Explore idempotency concepts and practice deleting entries with appropriate server responses.

Using the DELETE method

The final method, the deletion command, simply calls the session’s DELETE method.

Python 3.5
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 deleted
This 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 ...