Project structure

Our project will include the following components:

  • Database repository represents an abstraction layer over the database
  • Database migrator contains initialization logic for the database table
  • The REST API defines available HTTP calls and associated business logic
  • The configuration consolidates application parameters, such as server binding and database properties
  • The server wires all other components together, and spawns and binds an HTTP server to the configured address

We'll start by adding following dependencies to build.sbt (the exact versions can be found in the GitHub repository):

libraryDependencies ++= Seq(
"org.http4s" %% "http4s-blaze-server" % http4sVersion,
"org.http4s" %% "http4s-circe" % http4sVersion,
"org.http4s" %% "http4s-dsl" % http4sVersion,
"org.tpolecat" %% "doobie-core" % doobieVersion,
"org.tpolecat" %% "doobie-h2" % doobieVersion,
"org.tpolecat" %% "doobie-hikari" % doobieVersion,
"com.h2database" % "h2" % h2Version,
"org.flywaydb" % "flyway-core" % flywayVersion,
"io.circe" %% "circe-generic" % circeVersion,
"com.github.pureconfig" %% "pureconfig" % pureConfigVersion,
"ch.qos.logback" % "logback-classic" % logbackVersion,
"org.typelevel" %% "cats-core" % catsVersion,

"org.http4s" %% "http4s-blaze-client" % http4sVersion % "it,test",
"io.circe" %% "circe-literal" % circeVersion % "it,test",
"org.scalatest" %% "scalatest" % scalaTestVersion % "it,test",
"org.scalamock" %% "scalamock" % scalaMockVersion % Test
)

This list definitely looks longer than what you would expect for an example project. Let's inspect carefully why we need each of the dependencies we've put into it:

  • http4s is the library we will be using for the HTTP layer
  • doobie is a functional JDBC (Java DataBase Connectivity) decorator
  • H2 is an embedded database which we will use to avoid installing a standalone instance
  • Flyway is for database migrations (versioned SQL statements used to change the database structure)
  • Circe is a JSON Swiss Army knife
  • PureConfig is a typed configuration wrapper
  • Cats is a library containing general functional programming abstractions

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.107.193