All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.javalin.community.routing.dsl.defaults.DefaultDsl.kt Maven / Gradle / Ivy

There is a newer version: 6.4.0
Show newest version
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