POST: Starting a Game

Learn how to change the state of the game using the POST method.

The POST method is complicated because it touches all three tables. First, we have to validate the input. Does it specify both a username and a language? Is the language choice valid? If the request is not valid, an appropriate error message is given. The error code 400 is chosen since it indicates an invalid request. If the request is valid, then the associated user record is updated with this start.

Changing the object models

In making these updates, it’s useful to increase or decrease counts in the JSON fields and to handle when games start and end. Rather than adding all of this complexity into the API, it makes more sense to put it into the object models. After all, they’re closely tied to make changes in the object. In the langman_orm.py file, we first add the two new imports that we’ll need:

Get hands-on with 1400+ tech skills courses.