server

suspend fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> ResourceScope.server(factory: ApplicationEngineFactory<TEngine, TConfiguration>, port: Int = 80, host: String = "0.0.0.0", watchPaths: List<String> = listOf(WORKING_DIRECTORY_PATH), preWait: Duration = 30.seconds, grace: Duration = 500.milliseconds, timeout: Duration = 500.milliseconds, module: Application.() -> Unit = {}): EmbeddedServer<TEngine, TConfiguration>

Ktor ApplicationEngine as a Resource. This Resource will gracefully shut down the server When we need to shut down a Ktor service we need to properly take into account a grace period where we still handle requests instead of immediately cancelling any in-flight requests.

Parameters

factory

Application engine for processing the requests

port

Server listening port. Default is set to 80

host

Host address. Default is set to "0.0.0.0"

watchPaths

specifies path substrings that will be watched for automatic reloading

preWait

preWait a duration to wait before beginning the stop process. During this time, requests will continue to be accepted. This setting is useful to allow time for the container to be removed from the load balancer. This is disabled when io.ktor.development=true.

grace

grace a duration during which already inflight requests are allowed to continue before the shutdown process begins.

timeout

timeout a duration after which the server will be forcibly shutdown.

module

Represents configured and running web application, capable of handling requests.


suspend fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> ResourceScope.server(factory: ApplicationEngineFactory<TEngine, TConfiguration>, rootConfig: ServerConfig, configure: TConfiguration.() -> Unit = {}, preWait: Duration = 30.seconds, grace: Duration = 500.milliseconds, timeout: Duration = 500.milliseconds): EmbeddedServer<TEngine, TConfiguration>

Ktor ApplicationEngine as a Resource. This Resource will gracefully shut down the server When we need to shut down a Ktor service we need to properly take into account a grace period where we still handle requests instead of immediately cancelling any in-flight requests.

Parameters

factory

Application engine for processing the requests

rootConfig

definition of the core configuration of the server, including modules, paths, and environment details.

preWait

preWait a duration to wait before beginning the stop process. During this time, requests will continue to be accepted. This setting is useful to allow time for the container to be removed from the load balancer. This is disabled when io.ktor.development=true.

grace

grace a duration during which already inflight requests are allowed to continue before the shutdown process begins.

timeout

timeout a duration after which the server will be forcibly shutdown.