ktor-client

Configures Ktor HTTP clients and RemoteDataSources for Kotlin Multiplatform REST API consumption.

Updated Sep 12, 2026
One-click install
npx skills add https://github.com/Vierco/citoVisionApp --skill ktor-client-vierco
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ktor-client
Source: https://github.com/Vierco/citoVisionApp/tree/main/.claude/skills/ktor-client
Command: npx skills add https://github.com/Vierco/citoVisionApp --skill ktor-client-vierco

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up a type-safe, multiplatform HTTP client in Kotlin Multiplatform projects involves many error-prone decisions: engine selection per platform, plugin ordering, timeout configuration, authentication, and mapping network exceptions to domain errors. This Skill provides a complete, opinionated guide for configuring Ktor Client correctly in a Clean Architecture project. ## Core Features & Use Cases - HttpClient Configuration: Defines a single shared HttpClient in commonMain with Logging, ContentNegotiation (kotlinx.serialization), HttpTimeout, HttpRequestRetry, and optional Auth plugins in the correct order. - Platform Engine Injection: Declares platform-specific engines (OkHttp for Android/Desktop, Darwin for iOS) via Koin platform modules, keeping commonMain engine-agnostic. - Error Mapping: Captures Ktor exceptions (ClientRequestException, ServerResponseException, timeouts, IOException) inside the RemoteDataSource or Repository and translates them into typed DomainError values. - Use Case: When adding a new REST API integration to a KMP app, use this Skill to scaffold the HttpClient factory, wire the engine through Koin, implement the RemoteDataSource, and cover success, 4xx/5xx, and timeout cases with MockEngine tests. ## Quick Start Ask the assistant to configure a Ktor HTTP client with a RemoteDataSource for your Kotlin Multiplatform project following the ktor-client skill conventions.

Frequently Asked Questions about ktor-client

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure Ktor Client in Kotlin Multiplatform?▼

Create a single HttpClient in commonMain that accepts an injected HttpClientEngine, then install Logging, ContentNegotiation with kotlinx.serialization json, HttpTimeout, and HttpRequestRetry. Provide the engine per platform (OkHttp on Android/Desktop, Darwin on iOS) through your Koin platform module.

Which Ktor client engine should I use for Android and iOS?▼

Use OkHttp for Android and Desktop, and Darwin for iOS. Declare each engine in the platform-specific Koin module and inject it into the common HttpClient factory, so commonMain never imports a concrete engine.

How do I handle bearer token authentication with Ktor Client?▼

Install the Auth plugin with a bearer block that implements loadTokens and refreshTokens. Never add the Authorization header manually per request, and only install Auth when the API actually requires authentication.

Why is my Ktor request body not appearing in logs?▼

The Logging plugin must be installed before ContentNegotiation in the HttpClient configuration block. Installing it after can cause Ktor to lose the request and response body logs.

How do I map Ktor exceptions to domain errors?▼

Catch ClientRequestException, ServerResponseException, HttpRequestTimeoutException, and IOException inside the RemoteDataSource or Repository, then return typed DomainError results such as NetworkUnavailable or InvalidCredentials. Always rethrow CancellationException.

When should I not use Ktor Client?▼

This Skill covers only consuming existing REST APIs, not building a backend with Ktor Server. Cache combination logic belongs to the repository pattern, and dependency registration details belong to the Koin setup, not the client configuration.