Package io.ktor.server.engine

Types

Link copied to clipboard
interface ApplicationEngine

An engine which runs an application.

Link copied to clipboard
interface ApplicationEngineEnvironment

Represents an environment in which engine runs.

Link copied to clipboard
expect class ApplicationEngineEnvironmentBuilder

Engine environment configuration builder

actual class ApplicationEngineEnvironmentBuilder

Engine environment configuration builder

actual class ApplicationEngineEnvironmentBuilder

Engine environment configuration builder

Link copied to clipboard
class ApplicationEngineEnvironmentReloading(classLoader: ClassLoader, log: Logger, config: ApplicationConfig, connectors: List<EngineConnectorConfig>, modules: List<Application.() -> Unit>, watchPaths: List<String>, parentCoroutineContext: CoroutineContext, rootPath: String, developmentMode: Boolean) : ApplicationEngineEnvironment

Implements ApplicationEngineEnvironment by loading an Application from a folder or jar.

Link copied to clipboard

Factory interface for creating ApplicationEngine instances

Link copied to clipboard
abstract class BaseApplicationCall(application: <ERROR CLASS>)

Base class for implementing an ApplicationCall.

Link copied to clipboard
abstract class BaseApplicationEngine(environment: ApplicationEngineEnvironment, pipeline: EnginePipeline) : ApplicationEngine

Base class for implementing ApplicationEngine

Link copied to clipboard
abstract class BaseApplicationRequest(call: <ERROR CLASS>)

Base class for implementing ApplicationRequest

Link copied to clipboard
expect abstract class BaseApplicationResponse(call: <ERROR CLASS>)

Base class for implementing an ApplicationResponse

actual abstract class BaseApplicationResponse : ApplicationResponse

Base class for implementing an ApplicationResponse

actual abstract class BaseApplicationResponse(call: <ERROR CLASS>)
Link copied to clipboard
data class ConnectorType(name: String)

Represents a type of a connector, e.g HTTP or HTTPS.

Link copied to clipboard
class DefaultUncaughtExceptionHandler(logger: () -> <ERROR CLASS>) : CoroutineExceptionHandler

Handles all uncaught exceptions and logs errors with the specified logger ignoring CancellationException and IOException.

Link copied to clipboard
open class EngineConnectorBuilder(type: ConnectorType) : EngineConnectorConfig

Mutable implementation of EngineConnectorConfig for building connectors programmatically

Link copied to clipboard
interface EngineConnectorConfig

Represents a connector configuration.

Link copied to clipboard
class EnginePipeline(developmentMode: Boolean)

Application engine pipeline. One usually don't need to install interceptors here unless your are writing your own engine implementation

Link copied to clipboard
class EngineSSLConnectorBuilder(keyStore: KeyStore, keyAlias: String, keyStorePassword: () -> CharArray, privateKeyPassword: () -> CharArray) : EngineConnectorBuilder, EngineSSLConnectorConfig

Mutable implementation of EngineSSLConnectorConfig for building connectors programmatically

Link copied to clipboard
interface EngineSSLConnectorConfig : EngineConnectorConfig

Represents an SSL connector configuration.

Link copied to clipboard
class NativeApplicationEngineEnvironment(log: <ERROR CLASS>, config: <ERROR CLASS>, connectors: MutableList<EngineConnectorConfig>, modules: MutableList<<ERROR CLASS>.() -> Unit>, parentCoroutineContext: <ERROR CLASS>, rootPath: String, developmentMode: Boolean) : ApplicationEngineEnvironment
Link copied to clipboard
class ShutDownUrl(url: String, exitCode: ApplicationCall.() -> Int)

A plugin that allows you to configure a URL used to shut down the server. There are two ways to enable this plugin:

Functions

Link copied to clipboard
expect fun ApplicationEngine.addShutdownHook(stop: () -> Unit)

Adds automatic application shutdown hooks management. Should be used before starting the engine. Once application termination noticed, stop block will be executed. Please note that a shutdown hook only registered when the application is running. If the application is already stopped then there will be no hook and no stop function invocation possible. So stop block will be called once or never.

actual fun ApplicationEngine.addShutdownHook(stop: () -> Unit)

Adds automatic JVM shutdown hooks management. Should be used before starting the engine. Once JVM termination noticed, stop block will be executed. Please note that a shutdown hook only registered when the application is running. If the application is already stopped then there will be no hook and no stop function invocation possible. So stop block will be called once or never.

actual fun ApplicationEngine.addShutdownHook(stop: () -> Unit)

Adds automatic application shutdown hooks management. Should be used before starting the engine. Once application termination noticed, stop block will be executed. Please note that a shutdown hook only registered when the application is running. If the application is already stopped then there will be no hook and no stop function invocation possible. So stop block will be called once or never.

Link copied to clipboard
fun commandLineEnvironment(args: Array<String>): ApplicationEngineEnvironment

Creates an ApplicationEngineEnvironment instance from command line arguments

fun commandLineEnvironment(args: Array<String>, environmentBuilder: ApplicationEngineEnvironmentBuilder.() -> Unit = {}): ApplicationEngineEnvironment

Creates an ApplicationEngineEnvironment instance from command line arguments

Link copied to clipboard
inline fun ApplicationEngineEnvironmentBuilder.connector(builder: EngineConnectorBuilder.() -> Unit)

Adds a non-secure connector to this engine environment

Link copied to clipboard
fun defaultEnginePipeline(environment: <ERROR CLASS>): EnginePipeline

Default engine pipeline for all engines. Use it only if you are writing your own application engine implementation.

Link copied to clipboard
fun defaultExceptionStatusCode(cause: Throwable): <ERROR CLASS>?

Map cause to the corresponding status code or null if no default exception mapping for this cause type

Link copied to clipboard

Creates an embedded server with the given factory, environment and configure script

fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> embeddedServer(factory: ApplicationEngineFactory<TEngine, TConfiguration>, port: Int = 80, host: String = "0.0.0.0", watchPaths: List<String> = listOf(WORKING_DIRECTORY_PATH), configure: TConfiguration.() -> Unit = {}, module: <ERROR CLASS>.() -> Unit): TEngine
fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> CoroutineScope.embeddedServer(factory: ApplicationEngineFactory<TEngine, TConfiguration>, port: Int = 80, host: String = "0.0.0.0", watchPaths: List<String> = listOf(WORKING_DIRECTORY_PATH), parentCoroutineContext: CoroutineContext = EmptyCoroutineContext, configure: TConfiguration.() -> Unit = {}, module: <ERROR CLASS>.() -> Unit): TEngine

Creates an embedded server with the given factory, listening on host:port

fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> CoroutineScope.embeddedServer(factory: ApplicationEngineFactory<TEngine, TConfiguration>, vararg connectors: EngineConnectorConfig = arrayOf(EngineConnectorBuilder()), watchPaths: List<String> = listOf(WORKING_DIRECTORY_PATH), parentCoroutineContext: CoroutineContext = EmptyCoroutineContext, configure: TConfiguration.() -> Unit = {}, module: <ERROR CLASS>.() -> Unit): TEngine

Creates an embedded server with the given factory, listening on given connectors

Link copied to clipboard
suspend fun handleFailure(call: <ERROR CLASS>, error: Throwable)
Link copied to clipboard
fun <ERROR CLASS>.installDefaultTransformations()

Default receive transformation

fun <ERROR CLASS>.installDefaultTransformations()

Default send transformation

Link copied to clipboard
fun Job.launchOnCancellation(block: suspend () -> Unit): CompletableJob

Launch a coroutine with block body when the parent job is cancelled or a returned deferred is cancelled. It is important to complete or cancel returned deferred otherwise the parent job will be unable to complete successfully.

Link copied to clipboard
fun BaseApplicationEngine.Configuration.loadCommonConfiguration(deploymentConfig: <ERROR CLASS>)

Load engine's configuration suitable for all engines from deploymentConfig

Link copied to clipboard
suspend fun logError(call: <ERROR CLASS>, error: Throwable)
Link copied to clipboard
inline fun ApplicationEngineEnvironmentBuilder.sslConnector(keyStore: KeyStore, keyAlias: String, noinline keyStorePassword: () -> CharArray, noinline privateKeyPassword: () -> CharArray, builder: EngineSSLConnectorBuilder.() -> Unit)

Adds a secure connector to this engine environment

Link copied to clipboard
fun ApplicationEngine.stop(gracePeriod: Long, timeout: Long, timeUnit: TimeUnit)
Link copied to clipboard
fun ApplicationEngine.stopServerOnCancellation(): CompletableJob

Stop server on job cancellation. The returned deferred need to be completed or cancelled.

Link copied to clipboard
expect fun EngineConnectorConfig.withPort(otherPort: Int): EngineConnectorConfig

Returns new instance of EngineConnectorConfig based on this with modified port

actual fun EngineConnectorConfig.withPort(otherPort: Int): EngineConnectorConfig

Returns new instance of EngineConnectorConfig based on this with modified port

actual fun EngineConnectorConfig.withPort(otherPort: Int): EngineConnectorConfig

Returns new instance of EngineConnectorConfig based on this with modified port