App directives define custom routes. Just as for entities, all these routes start with the application’s name, /userdir/ in our example.

Static routes

The staticRoutes directive allows the mapping of request paths to filesystem directories. The directive accepts one or more <path, directory> pairs and can be called any number of times.

In the following example, the filesystem directories example_assets and images/avatars (both relative to the app’s root directory) are made accessible through the /userdir/assets and /userdir/avatars routes, respectively:

class UserDirectory extends HApp {
  staticRoutes("assets"  -> "example_assets",
               "avatars" -> "images/avatars")

An image file default.png in images/avatars can then be retrieved by clients with GET /userdir/avatars/default.png.

Spray routes

A Spray route is a directive that exposes the full power of Spray, the REST/HTTP toolkit on which HFactory Server is built. The sprayRoute directives takes a code block as parameter:

class UserDirectory extends HApp {
  sprayRoute {
    ...<spray routing directives>...

Please refer to Spray’s documentation for more information on Spray directives.

Root page

By default, an HApp looks for index.html (and index.htm if the .html version doesn’t exist) as the app’s root page, i.e. the page that is served when the app’s root route /<app> is hit.

While there is no directive per se to change the root page, the index method that returns the path to the root page to serve can be overriden.

Resource access

Due to a limitation in Spray’s handling of resources, Spray’s getFromResource and getFromResourceDirectory cannot access the app’s resources (the classloader Spray uses is hardcoded and has no knowledge of the app’s class path).

Hence instead of these directives, you should use getAppResource and getAppResourceDirectory – they work the same as the corresponding Spray directives.