Http4s Routes
Learn how to set up a base for http4s and product routes.
We'll cover the following...
Base for http4s routes
The routing DSL of http4s differs from the routing of Akka-HTTP. The latter makes it easier to model out a base for our routes.
Press + to interact
val productRoutes: HttpRoutes[IO] = HttpRoutes.of[IO] {case GET -> Root / "product" / id =>???case PUT -> Root / "product" / id =>???}val productsRoutes: HttpRoutes[IO] = HttpRoutes.of[IO] {case GET -> Root / "products" =>???case POST -> Root / "products" =>???}
As we can see, the DSL is closer to Scala syntax and quite easy to read. But before we move on to the details of each route, let’s think about how this can be modelled to become a bit more abstract.
Routing classes
While it is fine to have our routes bound to IO
...
Access this course and 1400+ top-rated courses and projects.