53 The quiz application: Part 2

 

In this capstone, you will

  • Lazily evaluate side effects using the type IO
  • Define an HTTP API to send and receive requests using http4s
  • Serialize and deserialize HTTP responses in JSON format using circe
  • Write tests to assert that your business logic is correct

In this capstone, you’ll complete the quiz application you started in unit 7 by defining its service and API layers. In particular, you’ll implement a server that offers its users an HTTP API to perform the following operations:

  • Inform about the status of your application.
  • Display a list of categories a user can choose.
  • Generate a quiz by randomly choosing 10 questions for a given category.
  • Calculate the quiz score based on the received answers.

In your application, you’ll focus on processing existing data rather than creating new data. Your database will contain preloaded data. However, you can easily add endpoints to allow users to add new categories, questions, and answers following the same patterns if you wish to do so.

You will structure your application in layers to have a clear separation of concerns (see figure 53.1):

53.1 Download the base project

53.2 Generic endpoints

53.3 Displaying the available categories

53.4 Creating a quiz

53.5 Answering a quiz

53.6 The HTTP server

53.7 Writing tests

53.8 Let’s give it a try!

Summary