8 Gordle as a service

 

This chapter covers

  • Creating and running an HTTP server that listens to messages on a given port
  • Listening to endpoints with GET and POST verbs
  • Building a response with a status code
  • Decoding different sources of data: path and query parameters, bodies, and headers
  • Testing using regular expressions

In 1962, J. C. R. Licklider mentioned the possibility of having computers communicate one with another over a network. Since then, computer science has traveled a long way, first through this Intergalactic Computer Network (coined by Licklider), then the pioneering network of Advanced Research Projects Agency Network (ARPANET), and, today, the internet. Networks are now used on a daily basis—when you pick up your phone to check the weather, the news, or even the time. The possibility of using a server from a remote location was paramount when, in 2020, the whole planet went into lockdown during COVID.

A server, in the end, is really just a machine that listens to communications on a given set of ports and is able to answer messages that it receives. In this chapter, we’ll implement such a server. To make things interesting, our server will have an API that allows a user to play a game of Gordle. In this chapter, we’ll focus on the server-side implementation rather than on the algorithmic aspect, which has already been covered in chapter 5.

8.1 Empty shell for the new service

8.1.1 Server, service, web service, endpoints, and HTTP handlers

8.1.2 Let’s code

8.2 Adding endpoints

8.2.1 Create a new game

8.2.2 Get the game status

8.2.3 Guess

8.3 Domain objects

8.3.1 Domain types

8.3.2 API adapters

8.4 Repository

8.4.1 In-memory database

8.4.2 Simplest repository

8.4.3 Service-level dependency

8.4.4 Add a mutex to the repository

8.5 Adapting the Gordle library

8.5.1 API of the library