concept http server in category scala

This is an excerpt from Manning's book Get Programming with Scala.
After learning about partial functions, you are now going to use them as part of your implementation of an HTTP server. Building an HTTP server without the help of an external library would require lots of extra time and code: thankfully, the Scala ecosystem offers a few external libraries to help you handle HTTP communication in an efficient and performant way. In this lesson, I’ll introduce you to http4s, a popular library to manage HTTP requests and responses. You’ll discover how to implement an HTTP server that replies to a GET “/ping” request with a response with status code “200 – Ok” and text “pong”. Finally, you’ll see how to run it using SBT. In the capstone, you’ll use http4s to create an HTTP server and define its API.
Figure 17.1: Summary of the main components of an http4s application. An HttpService[IO] matches a request, and it produces a response wrapped around an IO instance to represent possible side effects. A StreamApp[IO] uses a BlazeBuilder instance to bind to a given port and host and to mount multiple instances of HttpService[IO] to define the API of an HTTP server.
![]()
In this capstone, you’ll implement an HTTP server to play a popular variation of the classic game “Paper, Rock, Scissors!”, called “Rock, Paper, Scissors, Lizard, Spock!”. Two players play the game by each picking a symbol randomly: the selected symbols determine who the winner is. The allowed moves are Paper, Rock, Scissors, Lizard, Spock and they interact as follows: