AssetReader

Describes the API surface expected for a reader of static assets from some data source; responsible for efficiently reading assets from a resource path and producing resulting content.

Asset readers can cache the results of their reads, if desired, and may base caching decisions on the asset descriptors provided when resolving assets.

Resource assets

Typically, resources are embedded in the application JAR or native image, in zipped form, alongside embedded SSR assets and compiled JVM or native classes. The main AssetReader implementation knows how to interpret these assets based on a binary-encoded protocol buffer message also embedded within the application.

Replacing the main reader

The developer may find it desirable to write and provide their own AssetReader implementation, which can be accomplished via Micronaut's DI system (read on below). In particular, this may be a requirement for stable testing of a broader AssetManager implementation.

Replacing components of the AssetManager

To replace the stock AssetReader implementation, Micronaut's Replaces annotation can be used:

package your.package.here;

import elide.server.assets.AssetReader;
import io.micronaut.context.annotation.Replaces;

@Replaces(ServerAssetReader::class)
public class MyCoolAssetReader: AssetReader {
// (impl here)
}

See also

which coordinates between the AssetReader and AssetResolver.

for the generic return value model leveraged by AssetManager.

for the symbolic asset reference model leveraged by AssetManager.

Inheritors

Functions

Link copied to clipboard
abstract fun findByModuleId(moduleId: AssetModuleId): ServerAsset?

Return the asset module corresponding to the provided moduleId, if possible, or return null to indicate that the asset could not be located.

Link copied to clipboard
abstract fun pointerTo(moduleId: AssetModuleId): AssetPointer?

Resolve a reference to an asset identified by the provided moduleId, in the form of an AssetPointer; if no matching asset can be found, return null to indicate a not-found failure.

Link copied to clipboard
abstract suspend fun readAsync(descriptor: ServerAsset, request: HttpRequest<*>): Deferred<RenderedAsset>

Given a resolved asset descriptor which should be known to exist, read the associated asset content, and return it as an async Deferred task which can be awaited, and then consumed.

Link copied to clipboard
open fun resolve(request: HttpRequest<*>): ServerAsset?

Resolve the provided HTTP request to an asset path string, and then resolve the asset path string to a loaded ServerAsset, if possible; return null if the asset cannot be located.

abstract fun resolve(path: String): ServerAsset?

Resolve the provided path to a server asset, if possible, or return null to indicate that the asset could not be located; the given path value can be prefixed with the asset serving prefix (/_/asset by default) or not prefixed at all.