Type-Safe REST services in Scala with Http4s & Cats-IO

Akash Srivastava
Walmart Global Tech Blog
3 min readJan 8, 2020

--

source: meyou-paris

A common task for developers new to the Scala ecosystem is to set up a REST service which interacts with an underlying
database.

Lately, there have been a lot of libraries available that allows us to build the REST APIs, like the following:

  • Akka HTTP
  • Play
  • Http4s

In today’s blog, we go through the basic steps required to get started with using Http4s, to build a REST service interacting with a
database system, using Hikari Connection Pool.

What is Http4s?

Http4s is a minimal HTTP library for Scala, for building REST services. You can think of Http4s to be Scala’s answer to Java’s Servlets.

Http4s uses Cats IO, to ensure referential transparency by encapsulating side-effects and making the code more functional. (read more on this here)

So, without wasting much time, let’s get started !!

Our service will perform simple CREATE and READ operations. To keep things simple we will use a simple entity Car:

--

--