or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

builtin-plugins.mdcaching.mdcookies.mdengine-configuration.mdforms.mdhttp-client.mdindex.mdplugin-system.mdrequest-building.mdresponse-handling.mdresponse-observation.mdutilities.mdwebsockets.md
tile.json

tessl/maven-io-ktor--ktor-client-core-tvosarm64

Ktor HTTP Client Core for tvOS ARM64 - multiplatform asynchronous HTTP client library with coroutines support

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

To install, run

npx @tessl/cli install tessl/maven-io-ktor--ktor-client-core-tvosarm64@3.2.0

index.mddocs/

Ktor HTTP Client Core

Ktor HTTP Client Core is a multiplatform asynchronous HTTP client library written in Kotlin that provides comprehensive HTTP communication capabilities with full coroutines support. It enables developers to make HTTP requests across multiple platforms including JVM, JavaScript, Native (including tvOS ARM64), with a plugin-based architecture for extensibility.

Package Information

  • Package Name: io.ktor:ktor-client-core-tvosarm64
  • Package Type: maven
  • Language: Kotlin
  • Platforms: JVM, JavaScript, Native (tvOS ARM64, iOS, Android, etc.)
  • Installation: Add to your build.gradle.kts dependencies
dependencies {
    implementation("io.ktor:ktor-client-core-tvosarm64:3.2.0")
}

Core Imports

import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.client.plugins.*
import io.ktor.client.engine.*

Basic Usage

import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*

// Create client
val client = HttpClient()

// Make requests
val response: HttpResponse = client.get("https://api.example.com/users")
val text: String = response.bodyAsText()

// Make POST request
val postResponse = client.post("https://api.example.com/users") {
    setBody("{ \"name\": \"John\" }")
    header("Content-Type", "application/json")
}

// Don't forget to close the client
client.close()

Architecture

Ktor HTTP Client Core is built around several key architectural components:

  • HttpClient: Main client interface providing HTTP method convenience functions and lifecycle management
  • Engine Abstraction: Pluggable HTTP engines for different platforms (CIO, OkHttp, Curl, Fetch, etc.)
  • Plugin System: Extensible plugin architecture for cross-cutting concerns (authentication, caching, retries, etc.)
  • Pipeline Processing: Request and response pipeline with interceptor support for transformations
  • Multiplatform Design: Common API with platform-specific implementations using expect/actual declarations
  • Coroutine Integration: Full async/await support with proper cancellation and context propagation

Capabilities

HTTP Client Core

Core HTTP client functionality including client creation, configuration, request execution, and lifecycle management. Provides convenience methods for all HTTP verbs and advanced request building.

// HttpClient factory functions
expect fun HttpClient(block: HttpClientConfig<*>.() -> Unit = {}): HttpClient

fun <T : HttpClientEngineConfig> HttpClient(
    engineFactory: HttpClientEngineFactory<T>,
    block: HttpClientConfig<T>.() -> Unit = {}
): HttpClient

fun HttpClient(
    engine: HttpClientEngine,
    block: HttpClientConfig<*>.() -> Unit
): HttpClient

// HttpClient class
class HttpClient(
    public val engine: HttpClientEngine,
    private val userConfig: HttpClientConfig<out HttpClientEngineConfig> = HttpClientConfig()
) : CoroutineScope, Closeable {
    public val attributes: Attributes
    public val engineConfig: HttpClientEngineConfig
    public val monitor: Events
    public val requestPipeline: HttpRequestPipeline
    public val responsePipeline: HttpResponsePipeline
    public val sendPipeline: HttpSendPipeline
    public val receivePipeline: HttpReceivePipeline
    
    public fun isSupported(capability: HttpClientEngineCapability<*>): Boolean
    public fun config(block: HttpClientConfig<*>.() -> Unit): HttpClient
    override fun close()
}

HTTP Client Core

Request Building

Request building API providing type-safe DSL for constructing HTTP requests with URL configuration, headers, parameters, and body content.

class HttpRequestBuilder {
    var method: HttpMethod
    val url: URLBuilder
    val headers: HeadersBuilder
    
    fun parameter(key: String, value: Any?)
    fun header(key: String, value: String)
    fun accept(contentType: ContentType)
    fun contentType(contentType: ContentType)
    fun userAgent(agent: String)
    fun setBody(body: Any)
}

interface HttpRequest {
    val call: HttpClientCall
    val attributes: Attributes
    val content: OutgoingContent
    val headers: Headers
    val method: HttpMethod
    val url: Url
}

Request Building

Response Handling

Response handling API for accessing response data, headers, status, and converting response bodies to various types with streaming support.

abstract class HttpResponse {
    abstract val call: HttpClientCall
    abstract val content: ByteReadChannel
    abstract val coroutineContext: CoroutineContext
    abstract val headers: Headers
    abstract val requestTime: GMTDate
    abstract val responseTime: GMTDate
    abstract val status: HttpStatusCode
    abstract val version: HttpProtocolVersion
}

class HttpStatement(
    private val builder: HttpRequestBuilder,
    private val client: HttpClient
) {
    suspend fun execute(): HttpResponse
    suspend fun <T> execute(block: suspend HttpResponse.() -> T): T
}

// Response extension functions
suspend fun HttpResponse.bodyAsText(): String
suspend fun HttpResponse.bodyAsBytes(): ByteArray
fun HttpResponse.bodyAsChannel(): ByteReadChannel

Response Handling

Engine Configuration

HTTP engine abstraction layer allowing pluggable HTTP implementations across platforms with configuration for connection management, proxies, and platform-specific settings.

interface HttpClientEngine : CoroutineScope, Closeable {
    val config: HttpClientEngineConfig
    val dispatcher: CoroutineDispatcher
    suspend fun execute(data: HttpRequestData): HttpResponseData
}

interface HttpClientEngineFactory<T : HttpClientEngineConfig> {
    fun create(block: T.() -> Unit = {}): HttpClientEngine
}

open class HttpClientEngineConfig {
    var threadsCount: Int = 4
    var pipelining: Boolean = false
    var proxy: ProxyConfig? = null
}

interface HttpClientEngineCapability<T>

Engine Configuration

Plugin System

Extensible plugin architecture for adding cross-cutting functionality like authentication, caching, retries, logging, and custom request/response processing.

interface HttpClientPlugin<TConfig : Any, TPlugin : Any> {
    val key: AttributeKey<TPlugin>
    fun prepare(block: TConfig.() -> Unit = {}): TPlugin
    fun install(plugin: TPlugin, scope: HttpClient)
}

// Plugin installation
fun <T : HttpClientEngineConfig> HttpClientConfig<T>.install(
    plugin: HttpClientPlugin<*, *>,
    configure: Any.() -> Unit = {}
)

Plugin System

Built-in Plugins

Collection of built-in plugins for common HTTP client functionality including redirects, retries, timeouts, user agent, default requests, response validation, and plain text handling.

object HttpRedirect : HttpClientPlugin<HttpRedirect.Config, HttpRedirect>
object HttpRequestRetry : HttpClientPlugin<HttpRequestRetry.Config, HttpRequestRetry>
object HttpTimeout : HttpClientPlugin<HttpTimeout.Config, HttpTimeout>
object UserAgent : HttpClientPlugin<UserAgent.Config, UserAgent>
object DefaultRequest : HttpClientPlugin<DefaultRequest.Config, DefaultRequest>
object HttpCallValidator : HttpClientPlugin<HttpCallValidator.Config, HttpCallValidator>
object HttpPlainText : HttpClientPlugin<HttpPlainText.Config, HttpPlainText>
object HttpSend : HttpClientPlugin<HttpSend.Config, HttpSend>
object DataConversion : HttpClientPlugin<DataConversion.Config, DataConversion>
object BodyProgress : HttpClientPlugin<BodyProgress.Config, BodyProgress>

Built-in Plugins

Cookies Support

Cookie management functionality with configurable storage backends for automatic cookie handling across requests with support for custom storage implementations.

object HttpCookies : HttpClientPlugin<HttpCookies.Config, HttpCookies>

interface CookiesStorage {
    suspend fun get(requestUrl: Url): List<Cookie>
    suspend fun addCookie(requestUrl: Url, cookie: Cookie)
    fun close()
}

class AcceptAllCookiesStorage : CookiesStorage
class ConstantCookiesStorage(cookies: List<Cookie>) : CookiesStorage

Cookies Support

Caching

HTTP response caching functionality with configurable storage backends and cache control header support for improving performance and reducing network requests.

object HttpCache : HttpClientPlugin<HttpCache.Config, HttpCache>

interface HttpCacheStorage {
    suspend fun find(url: Url, vary: Map<String, String>): HttpCacheEntry?
    suspend fun findAll(url: Url): Set<HttpCacheEntry>
    suspend fun store(url: Url, data: HttpCacheEntry)
}

class UnlimitedCacheStorage : HttpCacheStorage
object DisabledCacheStorage : HttpCacheStorage

Caching

WebSocket Support

WebSocket client functionality for establishing and managing WebSocket connections with session management, ping/pong handling, and message serialization.

object WebSockets : HttpClientPlugin<WebSockets.Config, WebSockets>

interface ClientWebSocketSession : WebSocketSession {
    val call: HttpClientCall
}

// WebSocket extension functions  
suspend fun HttpClient.webSocket(
    method: HttpMethod = HttpMethod.Get,
    host: String? = null,
    port: Int? = null,
    path: String? = null,
    request: HttpRequestBuilder.() -> Unit = {},
    block: suspend ClientWebSocketSession.() -> Unit
)

suspend fun HttpClient.webSocketSession(
    method: HttpMethod = HttpMethod.Get,
    host: String? = null,
    port: Int? = null,
    path: String? = null,
    request: HttpRequestBuilder.() -> Unit = {}
): ClientWebSocketSession

WebSocket Support

Form Handling

Form data construction and submission utilities with support for URL-encoded forms, multipart forms, and file uploads using type-safe DSL builders.

class FormDataContent(formData: List<Pair<String, String>>) : OutgoingContent
class MultiPartFormDataContent(
    parts: List<PartData>,
    boundary: String = generateBoundary(),
    contentType: ContentType = ContentType.MultiPart.FormData.withParameter("boundary", boundary)
) : OutgoingContent

class FormBuilder {
    fun append(key: String, value: String)
    fun append(
        key: String,
        filename: String,
        contentType: ContentType? = null,
        size: Long? = null,
        block: suspend ByteWriteChannel.() -> Unit
    )
    fun appendInput(
        key: String,
        headers: Headers = Headers.Empty,
        size: Long? = null,
        block: suspend ByteWriteChannel.() -> Unit
    )
}

// Form submission functions
suspend fun HttpClient.submitForm(
    url: String,
    formParameters: Parameters = Parameters.Empty,
    encodeInQuery: Boolean = false,
    block: HttpRequestBuilder.() -> Unit = {}
): HttpResponse

suspend fun HttpClient.submitFormWithBinaryData(
    url: String,
    formData: List<PartData>,
    block: HttpRequestBuilder.() -> Unit = {}
): HttpResponse

Form Handling

Response Observation

Response observation functionality for monitoring and intercepting HTTP responses for logging, metrics collection, and custom processing.

object ResponseObserver : HttpClientPlugin<ResponseObserver.Config, ResponseObserver>

class ResponseObserver {
    class Config {
        internal val responseHandlers = mutableListOf<suspend (HttpResponse) -> Unit>()
        
        fun onResponse(block: suspend (response: HttpResponse) -> Unit)
    }
}

Response Observation

Utilities and Extensions

Utility classes and extension functions for common HTTP client operations including content handling, exception utilities, coroutine integration, and platform-specific helpers.

// Exception types
class ConnectTimeoutException(message: String, cause: Throwable? = null) : Exception(message, cause)
class SocketTimeoutException(message: String, cause: Throwable? = null) : Exception(message, cause)
class SaveBodyAbandonedReadException : Exception()

// Content utilities
class ClientUpgradeContent : OutgoingContent

// Client events
object HttpRequestCreated : EventDefinition<HttpRequestBuilder>()
object HttpRequestIsReadyForSending : EventDefinition<HttpRequest>()
object HttpResponseReceived : EventDefinition<HttpResponseContainer>()
object HttpResponseCancelled : EventDefinition<HttpResponseContainer>()

Utilities and Extensions