the akka http routes
Let’s skip ahead to look at the Akka HTTP routes. In a moment, we’ll come back to our service class to see how these routes are hooked up to the back-end repositories.
These routes define an application API that might be used by a JavaScript application front-end. We haven’t had the time to actually write a front end yet. If you would like to give it a shot, we would happily consider any pull requests!
UserRoute.scala
defines the Simple Blogging API for users and user
profiles. The following routes are defined:
POST /users
- creates a new userGET /users
- retrieves all the usersGET /users/$username
- retrieves a single userPUT /users/$username
- updates an existing userDELETE /users/$username
- deletes an existing userGET /users/$username/profile
- retrieves a user profilePUT /users/$username/profile
- creates or updates a user profileDELETE /users/$username/profile
- deletes a user profile
Please note that the GET /users
endpoint will not work with a
Cassandra persistence strategy, because Cassandra does not support
unfiltered queries.
These routes are defined in the standard idiom of Akka HTTP, and we will not go into the details here. Please take a look at the source code if you are interested. If you do not already have the Simple Blogging project checked out, you can view the source on GitHub.
For our purposes, the important thing to note is that the work for
each of these endpoints delegates to one of the methods in
UserService.scala
, which we will turn to next.