or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

application.mdconfig.mdengine.mdindex.mdrequest-response.mdrouting.mdutilities.md
tile.json

tessl/maven-io-ktor--ktor-server-core-iosarm64

Ktor server core module for iOS ARM64 target providing essential server-side functionality for building asynchronous web applications and microservices in Kotlin Multiplatform

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.ktor/ktor-server-core-iosarm64@3.2.x

To install, run

npx @tessl/cli install tessl/maven-io-ktor--ktor-server-core-iosarm64@3.2.0

index.mddocs/

Ktor Server Core

Ktor Server Core provides the essential foundation for building asynchronous web applications and microservices in Kotlin Multiplatform projects. This module includes core server-side functionality with support for routing, request/response handling, application lifecycle management, and a comprehensive plugin architecture. Built with Kotlin coroutines for asynchronous programming, it supports multiple hosting environments and offers a DSL-based configuration approach.

Package Information

  • Package Name: ktor-server-core-iosarm64
  • Package Type: maven
  • Language: Kotlin
  • Platform Target: iOS ARM64
  • Installation: implementation("io.ktor:ktor-server-core-iosarm64:3.2.0")

Core Imports

import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

Basic Usage

import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.http.*

// Create and start an embedded server (requires engine implementation)
fun main() {
    embeddedServer(SomeEngine, port = 8080) {
        routing {
            get("/") {
                call.respondText("Hello, Ktor!")
            }
            get("/users/{id}") {
                val id = call.parameters["id"]
                call.respondText("User ID: $id")
            }
        }
    }.start(wait = true)
}

// Configure application with plugins
fun Application.module() {
    install(CallLogging)
    
    routing {
        route("/api") {
            get("/health") {
                call.respond(mapOf("status" to "healthy"))
            }
        }
    }
}

Architecture

Ktor Server Core is built around several key architectural components:

  • Pipeline-Based Processing: All request/response handling flows through configurable pipelines with intercept phases
  • Plugin System: Extensible architecture where functionality is added through installable plugins
  • DSL Configuration: Kotlin DSL for declarative configuration of routes, plugins, and application behavior
  • Coroutine Integration: Built-in support for Kotlin coroutines enabling asynchronous, non-blocking operations
  • Multiplatform Support: Common API that works across JVM, JS, and Native targets including iOS ARM64
  • Engine Abstraction: Pluggable server engines (Netty, CIO, etc.) with unified configuration

Capabilities

Application and Lifecycle Management

Core application structure, configuration, and lifecycle management. Includes the main Application class, environment setup, and server configuration.

interface Application {
    val environment: ApplicationEnvironment
    val monitor: Events
    val parentCoroutineContext: CoroutineContext
    suspend fun disposeAndJoin()
}

interface ApplicationCall : CoroutineScope {
    val attributes: Attributes
    val request: ApplicationRequest
    val response: ApplicationResponse
    val application: Application
    val parameters: Parameters
    suspend fun <T> receiveNullable(typeInfo: TypeInfo): T?
    suspend fun respond(message: Any?, typeInfo: TypeInfo?)
}

fun serverConfig(block: ServerConfigBuilder.() -> Unit): ServerConfig

Application and Lifecycle Management

Configuration Management

Application configuration system supporting multiple formats and sources with hierarchical merging capabilities.

interface ApplicationConfig {
    fun property(path: String): ApplicationConfigValue
    fun propertyOrNull(path: String): ApplicationConfigValue?
    fun config(path: String): ApplicationConfig
    fun configList(path: String): List<ApplicationConfig>
    fun keys(): Set<String>
    fun toMap(): Map<String, Any?>
}

interface ApplicationConfigValue {
    val type: Type
    fun getString(): String
    fun getList(): List<String>
    fun getAs(type: TypeInfo): Any?
}

object ConfigLoader {
    fun load(path: String? = null): ApplicationConfig
}

Configuration Management

Server Engines and Embedded Servers

Application engine abstraction and embedded server functionality for hosting Ktor applications.

interface ApplicationEngine {
    val environment: ApplicationEnvironment
    suspend fun resolvedConnectors(): List<EngineConnectorConfig>
    fun start(wait: Boolean = false): ApplicationEngine
    suspend fun startSuspend(wait: Boolean = false): ApplicationEngine
    fun stop(gracePeriodMillis: Long, timeoutMillis: Long)
}

fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> 
embeddedServer(
    factory: ApplicationEngineFactory<TEngine, TConfiguration>,
    port: Int = 80,
    host: String = "0.0.0.0",
    watchPaths: List<String> = emptyList(),
    configure: TConfiguration.() -> Unit = {},
    module: Application.() -> Unit
): EmbeddedServer<TEngine, TConfiguration>

Server Engines and Embedded Servers

Request and Response Handling

Comprehensive request parsing and response building capabilities with content transformation pipelines.

interface ApplicationRequest {
    val call: ApplicationCall
    val pipeline: ApplicationReceivePipeline
    val queryParameters: Parameters
    val headers: Headers
    val local: RequestConnectionPoint
    val cookies: RequestCookies
}

interface ApplicationResponse {
    val call: ApplicationCall
    val pipeline: ApplicationSendPipeline
    val headers: ResponseHeaders
    val cookies: ResponseCookies
    fun status(): HttpStatusCode?
    fun status(value: HttpStatusCode)
}

// Extension functions for common operations
suspend inline fun <reified T> ApplicationCall.receive(): T
suspend fun ApplicationCall.receiveText(): String
suspend fun ApplicationCall.respond(message: Any)
suspend fun ApplicationCall.respondText(text: String, contentType: ContentType? = null, status: HttpStatusCode? = null)

Request and Response Handling

Routing System

Powerful routing DSL with pattern matching, parameter extraction, and nested route organization.

interface Route {
    val parent: Route?
    val selector: RouteSelector
    val developmentMode: Boolean
    val environment: ApplicationEnvironment
}

interface RoutingBuilder {
    fun route(path: String, build: Route.() -> Unit): Route
    fun method(method: HttpMethod, body: Route.() -> Unit): Route
    fun handle(body: suspend PipelineContext<Unit, PipelineCall>.() -> Unit)
}

// DSL functions
fun Application.routing(configuration: Routing.() -> Unit)
fun Route.get(path: String = "", body: suspend PipelineContext<Unit, PipelineCall>.() -> Unit): Route
fun Route.post(path: String = "", body: suspend PipelineContext<Unit, PipelineCall>.() -> Unit): Route
fun Route.put(path: String = "", body: suspend PipelineContext<Unit, PipelineCall>.() -> Unit): Route
fun Route.delete(path: String = "", body: suspend PipelineContext<Unit, PipelineCall>.() -> Unit): Route

Routing System

HTTP Utilities and Extensions

HTTP-specific utilities, link headers, server push support, and various helper functions.

// HTTP utilities
data class Link(
    val uri: String,
    val rel: List<String>,
    val type: ContentType? = null,
    val title: String? = null
)

// Extension properties for requests
val ApplicationRequest.uri: String
val ApplicationRequest.httpMethod: HttpMethod
val ApplicationRequest.path: String
val ApplicationRequest.host: String
val ApplicationRequest.port: Int
val ApplicationRequest.contentType: ContentType
val ApplicationRequest.userAgent: String?

// Logging and MDC support
interface MDCProvider {
    fun get(key: String): String?
    fun put(key: String, value: String?)
    fun remove(key: String)
    fun clear()
}

HTTP Utilities and Extensions

Plugin System

Ktor Server Core includes a comprehensive plugin system for extending functionality:

Core Plugin Interfaces

interface Plugin<TPipeline, TConfiguration, TPlugin> {
    val key: AttributeKey<TPlugin>
    fun install(pipeline: TPipeline, configure: TConfiguration.() -> Unit = {}): TPlugin
}

interface ApplicationPlugin<TConfiguration> : BaseApplicationPlugin<Application, TConfiguration, PluginInstance>

interface RouteScopedPlugin<TConfiguration> : Plugin<RoutingNode, TConfiguration, PluginInstance>

Plugin Creation Functions

fun createApplicationPlugin(
    name: String,
    body: PluginBuilder<Unit>.() -> Unit
): ApplicationPlugin<Unit>

fun <PluginConfigT> createApplicationPlugin(
    name: String,
    createConfiguration: () -> PluginConfigT,
    body: PluginBuilder<PluginConfigT>.() -> Unit
): ApplicationPlugin<PluginConfigT>

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

Plugin Installation

// Install plugins into application or routes
fun <TConfiguration> Application.install(
    plugin: ApplicationPlugin<TConfiguration>,
    configure: TConfiguration.() -> Unit = {}
): PluginInstance

fun <TConfiguration> Route.install(
    plugin: RouteScopedPlugin<TConfiguration>,
    configure: TConfiguration.() -> Unit = {}
): PluginInstance

// Access installed plugins
fun <TConfiguration> Application.plugin(plugin: ApplicationPlugin<TConfiguration>): PluginInstance
fun <TConfiguration> Application.pluginOrNull(plugin: ApplicationPlugin<TConfiguration>): PluginInstance?

Core Types

// Application environment and configuration
interface ApplicationEnvironment {
    val log: Logger
    val config: ApplicationConfig
}

// Request/Response connection information
interface RequestConnectionPoint {
    val scheme: String
    val version: String
    val port: Int
    val host: String
    val uri: String
    val method: HttpMethod
    val remoteHost: String
    val userAgent: String?
}

// Parameter collections
typealias Parameters = StringValues

// Pipeline phases and contexts
interface PipelineContext<TSubject, TContext>
interface PipelineInterceptor<TSubject, TContext>

// Hook system for plugins
interface Hook<HookHandler> {
    fun install(pipeline: ApplicationCallPipeline, handler: HookHandler)
}

// Event monitoring
interface Events {
    fun <T> subscribe(definition: EventDefinition<T>, handler: suspend (T) -> Unit): EventSubscription<T>
    fun <T> raise(definition: EventDefinition<T>, value: T)
}