Troubleshooting and best practices for Akka HTTP
When using Akka HTTP, there are a few best practices and a troubleshooting tip that I'd like to share with you. With the information in this section, you will be better equipped to employ Akka HTTP within your codebase.
Trouble with the tilde
Back in Chapter 7, REST Easy with Akka HTTP, when discussing the high-level Inbound HTTP API, we talked about composing routes together with the tile operator (~
). At the end of the section titled Composing directives together, I gave a tip about forgetting to include the ~
and the effect it can have. Here, I'll provide a more concrete example of this problem and the symptom you will see when you encounter it. Consider the following set of routes that you set up to handle your inbound requests:
pathPrefix("book"){ (get & path(Segment)){ id => . . . } (post & entity(as[CatalogNewBook])){ req => . . . } }
The intention here was to set up two routes...