How it works...
In this recipe, you learned how routing DSL is not only elegant and useful but also extensible. We saw how to create new directives that we can integrate seamlessly into our routes. In this particular case, we defined two new directives--meter and timer. meter is responsible for measuring the rate of events. timer is responsible for measuring how long a computation takes. As we can see in the code, we reused other basic directives provided by Akka HTTP, such as extractMethod, extractUri, or mapRouteResult. This is advisable since the basic directives cover most of the common use cases; however, it is possible to create a directive from scratch by extending the Directive[L](implicit val ev: Tuple[L]). abstract class.
Both ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access