GET: Seeing Game Status

Learn about the GET method for the Lang-Man application.

Using the GET method

The next method to define is the GET method, on the route for the specific game. This one is much simpler. The game_id from the route is used to query the database for the given game. If it exists, it’s converted to a dict using a custom method for the game ORM class. Otherwise, a 404 error is returned.

The custom conversion to a dict finds all attributes of the object that do not begin with an underscore, and places them into a dictionary. It also computes the game result, which will be one of the following: won, lost, or active. The dates and times must be converted to strings, because JSON doesn’t directly handle dates.

We put this conversion function into util.py:

Get hands-on with 1200+ tech skills courses.