listDirectoryContents
§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
- final Route route = route(
- path("tmp", () -> listDirectoryContents("/tmp")),
- path("custom", () -> {
- // implement your custom renderer here
- final DirectoryRenderer renderer = renderVanityFooter -> {
- throw new NotImplementedError();
- };
- return listDirectoryContents(renderer, "/tmp");
- })
- );
-
- // tests:
- testRoute(route).run(HttpRequest.GET("/logs/example"))
- .assertEntity("example file contents");
Contents