PageController
Defines the built-in concept of a Page
-type handler, which is capable of performing SSR, serving static assets, and handling page-level RPC calls.
Page controllers use a dual-pronged mechanism to hook into application code. First, the controller annotates with Page, which provides AOT advice and route bindings; a suite of on-class functions and injections related to page can also then be inherited from PageController, although this is only necessary to leverage static asset serving and SSR. Most of these resources are acquired statically, which keeps things fast.
When the developer calls a method like ssr
or asset
, for example, the bean context is consulted, and an AssetManager
or JsRuntime
is resolved to satisfy the response.
Controller lifecycle
Bean objects created within a Micronaut dependency injection context have an associated scope, which governs something called the "bean lifecycle." The bean lifecycle, and by extension, the bean scope, determines when an instance is constructed, how long it survives, and when garbage is collected.
By default, raw Micronaut controllers are API endpoints. For example, the default input/output Content-Type
is JSON and the lifecycle is set to Singleton
. This means a controller is initialized the first time it is accessed, and then lives for the duration of the server run.
Pages follow this default and provide on-class primitives to the user, via PageController, which help with the management of state, caching, sessions, and so forth.
Inheritors
Functions
Responds to a client with an HTML response, using specified block to build an HTML page via Kotlin's HTML DSL.