How to do it...

For this recipe, perform the following steps:

  1. First, start writing a trait that will handle all the requests for a given path and leave the methods for handling get, post, put, and delete requests unimplemented. Create a file named InMemoryStorageRestApi.scala inside the com.packt.chapter9 package with the following content:
        package com.packt.chapter9        import akka.http.scaladsl.server.Directives._        import akka.http.scaladsl.server._        import scala.collection.mutable        trait InMemoryStorageRestApi[K, V] {          implicit val fixedPath: String          def composedRoute(cache: mutable.Map[K, V]) =            versionOneRoute {              temperaturePathRoute {                handleAllMethods(cache)              }            }          private def versionOneRoute(route: Route) =            pathPrefix("v1") {              route            }          private ...

Get Akka Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.