listDirectoryContents
Signature
Description
Completes GET requests with a unified listing of the contents of all given directories. The actual rendering of the
directory contents is performed by the in-scope Marshaller[DirectoryListing]
.
To just serve files use getFromDirectory.
To serve files and provide a browseable directory listing use getFromBrowseableDirectories instead.
The rendering can be overridden by providing a custom Marshaller[DirectoryListing]
, you can read more about it in
getFromDirectory 's documentation.
Note that it's not required to wrap this directive with get
as this directive will only respond to GET
requests.
Example
val route =
path("tmp") {
listDirectoryContents("/tmp")
} ~
path("custom") {
// implement your custom renderer here
val renderer = new DirectoryRenderer {
override def marshaller(renderVanityFooter: Boolean): ToEntityMarshaller[DirectoryListing] = ???
}
listDirectoryContents("/tmp")(renderer)
}
// tests:
Get("/logs/example") ~> route ~> check {
responseAs[String] shouldEqual "example file contents"
}
Contents