com.thoughtworks.dsl.domains.akka
This http object provides Dsl type class instances to allow Dsl.Keywords to be used in functions that return akka.http.scaladsl.server.StandardRoute or akka.http.scaladsl.server.Directive, as long as those keywords can be used in functions that return scala.concurrent.Future.
You may want to import type classes in this http object when creating custom Akka HTTP directive.
import com.thoughtworks.dsl.domains.akka.http._
Suppose you are creating a directive to asynchronously save the request body to a temporary file and return the file path.
import java.nio.file.Path import java.nio.file.Files import com.thoughtworks.dsl.keywords.Await import com.thoughtworks.dsl.keywords.Return import com.thoughtworks.dsl.keywords.akka.http.TApply import akka.stream.scaladsl.FileIO import akka.http.scaladsl.server.Directive1 import akka.http.scaladsl.server.Directives._ def saveRequestBody: Directive1[Path] = { val path = Files.createTempFile(null, null) val entity = !TApply(extractRequestEntity) val ioResult = !Await(entity.dataBytes.runWith(FileIO.toPath(path))) val _ = ioResult.status.get !Return(path) }
Then the custom directive can be used in a route.
def uploadRoute = post { val tmpPath = !TApply(saveRequestBody) complete(s"${Files.size(tmpPath)} bytes uploaded.") } Post("/", ('A' to 'Z').toArray) ~> uploadRoute ~> check { responseAs[String] should be("26 bytes uploaded.") }
You don't need this http object if you only want to use a Dsl.Keywords in a function that returns akka.http.scaladsl.server.Route, because it is a type alias of scala.Function1, which is supported via Dsl#derivedFunction1Dsl.
This http object can be found in the following library:
libraryDependencies += "com.thoughtworks.dsl" %% "domains-akka-http" % "latest.release"
This http object provides Dsl type class instances to allow Dsl.Keywords to be used in functions that return akka.http.scaladsl.server.StandardRoute or akka.http.scaladsl.server.Directive, as long as those keywords can be used in functions that return scala.concurrent.Future.
You may want to import type classes in this http object when creating custom Akka HTTP directive.
import com.thoughtworks.dsl.domains.akka.http._
Suppose you are creating a directive to asynchronously save the request body to a temporary file and return the file path.
Then the custom directive can be used in a route.
You don't need this http object if you only want to use a Dsl.Keywords in a function that returns akka.http.scaladsl.server.Route, because it is a type alias of scala.Function1, which is supported via Dsl#derivedFunction1Dsl.
,This http object can be found in the following library: