Akka HTTP provides a powerful Scala DSL to create routes to handle HTTP requests. The DSL contains a set of Directive
s to extract information or manipulate requests or responses.
For example, the following cpsRoute
accepts a GET
request and extracts query parameters p1
and p2
with the help of get
and parameters
directive. If an HTTP client send a GET
request to the URL /?p1=Hello&p2=World
, it will receive the response of plain text Hello, World!
.
import akka.http.scaladsl.server._, Directives._
def cpsRoute: Route = {
get {
parameters("p1", "p2") { (p1, p2) =>