Javalin
Javalin is a very popular, simple, lightweight and flexible micro web framework for Java and Kotlin. It's un-opinionated and runs on top of Jetty, one of the most used and stable web-servers for the JVM.
Build configuration
Kilua RPC provides three different modules for Javalin:
kilua-rpc-javalin, which doesn't use dependency injection (DI) and requires manual services registration,kilua-rpc-javalin-koin, which uses Koin dependency injection framework to access services implementations.kilua-rpc-javalin-metro, which uses Metro dependency injection framework to access services implementations.
You need to add one of these modules to your project.
val commonMain by getting {
dependencies {
implementation("dev.kilua:kilua-rpc-javalin:$kiluaRpcVersion")
// implementation("dev.kilua:kilua-rpc-javalin-koin:$kiluaRpcVersion")
// implementation("dev.kilua:kilua-rpc-javalin-metro:$kiluaRpcVersion")
}
}Service implementation
Service class
The implementation of the service class comes down to implementing required interface methods.
When using Metro, you need to add some annotations and the MetroRpcService interface to your service class.
Injecting server objects
You can use constructor parameters to inject server objects - Context , JavalinState and WsContext (see Websockets chapter) into your service classes. These objects give you access to the application configuration, its state, the current request and the user session.
Application configuration
The main function
This function is the application starting point. It's used to initialize and configure application modules and features. Minimal implementation for Kilua RPC integration contains applyRoutes function calls and service initialization with an appropriate initRpc function.
When using manual service registration, you call initRpc with a lambda function, which binds interfaces with their implementations. Different overloads of registerService function allow injecting server objects into your service classes.
When using Koin, you call initRpcKoin to initialize Koin modules. Constructor parameter injection is automatically supported by Koin.
When using Metro, you call initRpcMetro to initialize Metro dependency graph. Constructor parameter injection is automatically supported by Metro.
Security
When configuring security with AccessManager you can call applyRoutes with additional parameter containing roles.
Last updated