Getting Started
Set up a Funktor application from scratch.
Add the dependency
The easiest way to get all modules is the funktor-all meta-dependency. Or pick individual modules.
// build.gradle.kts
dependencies {
// All modules at once
implementation("io.peekandpoke.funktor:all:0.117.0")
// Or pick what you need
implementation("io.peekandpoke.funktor:core:0.117.0")
implementation("io.peekandpoke.funktor:rest:0.117.0")
implementation("io.peekandpoke.funktor:auth:0.117.0")
} Define your app
A Funktor app starts with funktorApp. You configure the server modules and define your Kontainer
blueprint.
fun main(args: Array<String>) = funktorApp {
server {
// Wire up funktor modules
funktorCore()
funktorRest()
funktorAuth {
useKarango()
}
// Your own modules
module(MyAppModule)
}
cli {
// CLI commands run with --cli flag
}
} Define your Kontainer blueprint
Services are registered in Kontainer modules. Each Funktor module registers its own services. You add your application services alongside them.
val MyAppModule = module {
// Your services
singleton(UserRepository::class)
dynamic(UserService::class)
// Your API feature
singleton(MyApiFeature::class)
} Define API routes
Routes use the typed API system from the REST module. Define endpoints with type-safe parameters, request bodies, and response types.
class MyApi : ApiRoutes("my-api") {
val getUsers = MyApiClient.GetUsers.mount {
docs { name = "List users" }
.authorize { public() }
.handle {
val users = userService.listAll()
ApiResponse.ok(users)
}
}
} Configure the server
The Ktor server module configures routing, CORS, and mounts your API features.
fun Application.module() = app.module(this) { app, config, init ->
install(SSE)
install(CORS) {
// your CORS config
}
routing {
// API features are auto-discovered from Kontainer
apiApp.mountAll(this)
}
} All
ApiFeature instances registered in Kontainer are automatically discovered and mounted.
You never manually wire route groups.