Akka-HTTP Routes
Learn how to start the server and implement the routes for returning and updating a single product.
We'll cover the following...
Basic routes
Defining the routes is pretty simple if you are used to the Akka-HTTP routing DSL syntax.
Press + to interact
val route = path("product" / JavaUUID) { id: ProductId =>get {???} ~ put {???}} ~ path("products") {get {???} ~post {???}}
We will fill in the details later on.
Starting the server
Now, let’s start the actual server to make use of our routes.
Press + to interact
val host = system.settings.config.getString("api.host")val port = system.settings.config.getInt("api.port")val srv = Http().bindAndHandle(route, host, port)val pressEnter = StdIn.readLine()srv.flatMap(_.unbind()).onComplete(_ => system.terminate())
The code will fire ...