{title:'Static files', updated:'9.0.0'}

The {@link oajr.servlet.BasicRestServlet} and {@link oajr.servlet.BasicRestObject} classes come with built-in support for serving up static files through the following REST operation:

| @RestGet(path="/htdocs/*") | public HttpResource getHtdoc(@Path("/*") String path, Locale locale) throws NotFound { | return getContext().getStaticFiles().resolve(path, locale).orElseThrow(NotFound::new); | }

The static file finder can be accessed through the following methods:

- {@link oajr.RestContext}
  - {@link oajr.RestContext#getStaticFiles() getStaticFiles()}
- {@link oajr.RestRequest}
  - {@link oajr.RestRequest#getStaticFiles() getStaticFiles()}

By default, the {@link oajr.staticfile.StaticFiles} bean is configured as follows:

| StaticFiles | .create() | .beanStore(beanStore) // Allow injected beans in constructor. | .type(BasicStaticFiles.class) // Default implementation class. | .dir("static") // Look in working /static directory. | .dir("htdocs") // Look in working /htdocs directory. | .cp(resourceClass, "htdocs", true) // Look in htdocs subpackage. | .cp(resourceClass, "/htdocs", true) // Look in htdocs package. | .caching(1_000_000) // Cache files in memory up to 1MB. | .exclude("(?i).*\\.(class|properties)") // Ignore class/properties files. | .headers(cacheControl("max-age=86400, public")); // Add cache control.

Static files can be configured programmatically through the following APIs:

- {@link oajr.RestContext.Builder}
  - {@link oajr.RestContext.Builder#createStaticFiles(BeanStore,Supplier) createStaticFiles(BeanStore,Supplier)}
  - {@link oajr.RestContext.Builder#staticFiles() staticFiles()}
  - {@link oajr.RestContext.Builder#staticFiles(Consumer) staticFiles(Consumer)}