io.javalin.community.routing.dsl.defaults.DefaultDsl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of routing-dsl Show documentation
Show all versions of routing-dsl Show documentation
Module provides set of DSLs for building routing in Javalin application
package io.javalin.community.routing.dsl.defaults
import io.javalin.community.routing.dsl.DslExceptionHandler
import io.javalin.community.routing.dsl.DslRoute
import io.javalin.community.routing.dsl.DslContainer
import io.javalin.community.routing.dsl.RoutingDslFactory
import io.javalin.community.routing.dsl.defaults.DefaultDsl.DefaultConfiguration
import io.javalin.community.routing.dsl.defaults.DefaultDsl.DefaultScope
import io.javalin.http.Context
import io.javalin.http.ExceptionHandler
import io.javalin.http.Handler
typealias DefaultRoute = DslRoute
abstract class DefaultRoutes : DslContainer
/**
* Default implementation of [RoutingDslFactory] that uses [DefaultScope] as scope and [DefaultConfiguration] as configuration.
*/
object DefaultDsl : RoutingDslFactory, DefaultScope, Unit> {
open class DefaultConfiguration : DefaultContextScopeConfiguration, DefaultScope, Unit>()
open class DefaultScope(override val ctx: Context) : DefaultContextScope, Context by ctx
override fun createConfiguration(): DefaultConfiguration =
DefaultConfiguration()
override fun createHandler(route: DslRoute): Handler =
Handler { ctx ->
route.handler(DefaultScope(ctx))
}
override fun createExceptionHandler(handler: DslExceptionHandler): ExceptionHandler =
ExceptionHandler { exception, ctx ->
handler(DefaultScope(ctx), exception)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy