createRouteScopedPlugin

fun <PluginConfigT : Any> createRouteScopedPlugin(name: String, createConfiguration: () -> PluginConfigT, body: PluginBuilder<PluginConfigT>.() -> Unit): RouteScopedPlugin<PluginConfigT>

Creates a RouteScopedPlugin that can be installed into a io.ktor.server.routing.Route.

The example below create a plugin that prints a requested URL each time your application receives a call:

val RequestLoggingPlugin = createRouteScopedPlugin("RequestLoggingPlugin") {
onCall { call ->
println(call.request.uri)
}
}

route("index") {
install(RequestLoggingPlugin)
}

You can learn more from Custom plugins.

Parameters

name

A name of a plugin that is used to get its instance when it is installed to io.ktor.server.routing.Routing.

createConfiguration

Defines how the initial PluginConfigT of your new plugin can be created. Please note that it may be modified later when a user of your plugin calls install.

body

Allows you to define handlers (onCall, onCallReceive, onCallRespond and so on) that can modify the behaviour of an Application where your plugin is installed.


fun createRouteScopedPlugin(name: String, body: PluginBuilder<Unit>.() -> Unit): RouteScopedPlugin<Unit>

Creates a RouteScopedPlugin that can be installed into a io.ktor.server.routing.Route.

The example below create a plugin that prints a requested URL each time your application receives a call:

val RequestLoggingPlugin = createRouteScopedPlugin("RequestLoggingPlugin") {
onCall { call ->
println(call.request.uri)
}
}

route("index") {
install(RequestLoggingPlugin)
}

You can learn more from Custom plugins.

Parameters

name

A name of a plugin that is used to get an instance of the plugin installed to the io.ktor.server.routing.Route.

body

Allows you to define handlers (onCall, onCallReceive, onCallRespond and so on) that can modify the behaviour of an Application where your plugin is installed.