PUT: Guessing a Letter
Explore how to implement the PUT method in a REST API for a letter guessing game. Understand handling edge cases like invalid requests or ended games, updating game states, and managing database commits efficiently. This lesson helps you build robust API endpoints that manage game logic and provide accurate responses.
We'll cover the following...
We'll cover the following...
Designing the PUT method
Next, we will define the most complex method, the PUT method, where a letter guess is handled. This must account for special cases, such as:
- A non-existent game
- A game that has already ended
- A request with no letter in the payload
- A guessed letter that is more than one character
- A repeat guess
- No letter specified.
Handling special cases
What checks is this code missing? This method is typical because most of it is devoted to handling special cases, and only a small portion addresses the “typical” case. ...