In addition, this TApply keyword can be used together with other keywords.
For example, you can use com.thoughtworks.dsl.keywords.Using to automatically manage resources.
With the help of the Using keyword, the currentDirectoryRoute will open the current directory according to the glob pattern extract from the query parameter, and automatically close the directory after the HTTP request is processed completely.
Get("/current-directory/file-names?glob=*.md") ~> currentDirectoryRoute ~> check {
responseAs[String] should be("README.md")
}
Get("/current-directory/file-names?glob=*.*") ~> currentDirectoryRoute ~> check {
responseAs[String].split(',') should (contain("secret.sbt") and contain("build.sbt") and contain("README.md"))
}
Get("/current-directory/number-of-files?glob=*.sbt") ~> currentDirectoryRoute ~> check {
responseAs[String] should be("2")
}
,
Ordinary Akka HTTP DSL requires additional brackets to perform any directive.
For example, the following extractParametersWithBrackets extracts query parameters p1 and p2 with the help of the directive akka.http.scaladsl.server.Directives.parameters.
This TApply keyword can be used to extract the value of akka.http.scaladsl.server.Directives, without additional indentation levels of curly brackets.
In addition, this TApply keyword can be used together with other keywords. For example, you can use com.thoughtworks.dsl.keywords.Using to automatically manage resources.
With the help of the
Using
keyword, thecurrentDirectoryRoute
will open the current directory according to the glob pattern extract from the query parameter, and automatically close the directory after the HTTP request is processed completely.Ordinary Akka HTTP DSL requires additional brackets to perform any directive. For example, the following
extractParametersWithBrackets
extracts query parametersp1
andp2
with the help of the directive akka.http.scaladsl.server.Directives.parameters.The brackets can be avoided with the help of this TApply keyword:
This TApply class can be found in the following library: