getFromResource
Signature
Description
Completes GET requests with the content of the given classpath resource.
For details refer to getFromFile which works the same way but obtaining the file from the filesystem instead of the applications classpath.
Note that it's not required to wrap this directive with get
as this directive will only respond to GET
requests.
Example
import akka.http.scaladsl.server.directives._
import ContentTypeResolver.Default
val route =
path("logs" / Segment) { name =>
getFromResource(s"$name.log") // uses implicit ContentTypeResolver
}
// tests:
Get("/logs/example") ~> route ~> check {
responseAs[String] shouldEqual "example file contents"
}
Contents