Package dev.relism.flash.extension
Class FlashApp
Single entry point for Flash. Owns one flat Startup sequence (both
FastPathRouterImpl —
all routes (app-level and scoped) compile into a single FSM at startup.
FlashApp.create(8080)
.install(new JacksonExtension())
.use(cors)
.get("/ping", (req, res) -> "pong")
.get("/secured", (req, res) -> user(), oidc.protect())
.scan("dev.example.handlers")
.mount("/api", scope -> scope.get("/health", (req, res) -> "ok"))
.startAndBlock(); // blocks main thread
Startup sequence (both start() and startAndBlock())
- All
FlashExtension.configure(dev.relism.flash.extension.FlashRegistrar<?>, dev.relism.flash.extension.FlashContext)declarations. FlashContext.resolveAll()— topo-sort, cycle detection.- Ready callbacks register routes with resolved services.
- Compile all routes into one flat FSM — zero prefix scanning at runtime.
- Accept loop started.
Default error handlers
Dev mode (-Dflash.env=dev): rich HTML with stack traces.
Prod mode (default): generic JSON — no internal details leaked.
Override via onException(dev.relism.flash.routing.AbstractRouter.ExceptionHandler) / onNotFound(dev.relism.flash.models.SimpleHandler.FunctionalHandler).-
Method Summary
Modifier and TypeMethodDescriptionprotected voidRegisters a middleware in this registrar's own scope (global or scope-level).protected voidaddRoute(HttpMethod method, String path, RequestHandler handler, List<MiddlewareNode> mw) Adds a route immediately to this registrar's deferred compilation list.protected voidaddWsRoute(String path, WebSocketEndpoint endpoint) static FlashAppcreate(int port) static FlashAppcreate(FlashConfiguration cfg) ctx()Returns theFlashContextfor this registrar.install(FlashExtension ext) Registers a declarative extension contribution.mount(String namespace, Consumer<FlashScope> configure) Mounts a scoped group of routes undernamespace.start()Boots the server and starts accepting connections.voidBoots the server and blocks the calling thread until the server is stopped.stop()ws(String path, WebSocketHandler handler) Registers a WebSocket endpoint atpath.Methods inherited from class dev.relism.flash.extension.FlashRegistrar
connect, connectWith, delete, deleteWith, get, getWith, head, headWith, instantiate, instantiateWs, options, optionsWith, patch, patchWith, post, postWith, purge, purgeWith, put, putWith, query, queryWith, scan, trace, traceWith, use, use
-
Method Details
-
create
-
create
-
mount
Mounts a scoped group of routes undernamespace. Routes accumulate in aFlashScopebuilder and merge into this app's single flat router at startup — pure syntactic sugar, no extra router involved. -
ws
Registers a WebSocket endpoint atpath. Runs on the same virtual-thread model as HTTP handlers. A path may have both an HTTP handler and a WS endpoint simultaneously. -
onException
-
onNotFound
-
ctx
Description copied from class:FlashRegistrarReturns theFlashContextfor this registrar.- Specified by:
ctxin classFlashRegistrar<FlashApp>
-
install
Registers a declarative extension contribution. -
start
Boots the server and starts accepting connections. Returns immediately — the accept loop runs on a background platform thread.Use
startAndBlock()inmain()if you have no other work to do after startup.- Returns:
thisfor storing or chaining (e.g..start().ctx().require(...))
-
startAndBlock
public void startAndBlock()Boots the server and blocks the calling thread until the server is stopped. Suitable for the end ofmain()— no need to keep the JVM alive manually. -
stop
-
addRoute
protected void addRoute(HttpMethod method, String path, RequestHandler handler, List<MiddlewareNode> mw) Description copied from class:FlashRegistrarAdds a route immediately to this registrar's deferred compilation list. Subclasses may prepend a namespace prefix and inject scope middlewares before storing.- Specified by:
addRoutein classFlashRegistrar<FlashApp>
-
addWsRoute
- Specified by:
addWsRoutein classFlashRegistrar<FlashApp>
-
addMiddleware
Description copied from class:FlashRegistrarRegisters a middleware in this registrar's own scope (global or scope-level).- Specified by:
addMiddlewarein classFlashRegistrar<FlashApp>
-