clankerguru/opsx/ktor-client
Claude Code and agent skill by clankerguru/opsx
- community
Checking that the SKILL.md file is still in the repository.
Use when building an HTTP client with Ktor — HttpClient creation, engines (CIO/OkHttp/Apache5/Java/Darwin/Js/WinHttp/Curl), client plugins (ContentNegotiation, Logging, Auth, HttpTimeout, DefaultRequest, HttpRequestRetry, Resources, WebSockets, SSE, HttpCache, HttpCookies, UserAgent), making requests (get/post/put/patch/delete/head/options), request builders (url, headers, parameter, bearerAuth, basicAuth, setBody, accept, contentType), response handling (body, bodyAsText, bodyAsChannel, status, headers), streaming and multipart/form-data submission, typed requests with kotlinx.serialization, bearer token refresh, websocket and SSE sessions, and MockEngine-based testing.
Install
npx vskill@latest install clankerguru/opsx/ktor-clientSKILL.md
The same SKILL.md was published earlier as clankerguru/opsx/ktor-client.
When to use this skill
- Calling any HTTP or WebSocket API from Kotlin (JVM, Android, Native,
iOS, JS).
- Needing a single multiplatform client that speaks JSON / XML / CBOR /
Protobuf via kotlinx.serialization.
- Replacing a per-platform client (OkHttp on Android + URLSession on
iOS) with one shared codebase.
When NOT to use this skill
- Server-side HTTP handling — that's
/ktor-server. - Creating a reusable plugin (client or server) — that's
/ktor-plugin.
- Pure gRPC or proprietary binary protocols — Ktor client speaks HTTP.
Installation
Gradle (build.gradle.kts):
Pin $ktorVersion via a version catalog. Every client artifact ships from the same release — keep versions aligned.
Engines
| Engine | Platform | Notes | |
|---|---|---|---|
CIO | JVM, Native | Pure Kotlin, coroutine-native, default pick. | |
OkHttp | JVM, Android | Battle-tested; HTTP/2; best on Android. | |
Apache5 | JVM | Apache HttpClient 5; sync + async; HTTP/2. | |
Java | JVM (11+) | Uses java.net.http.HttpClient. | |
Darwin | iOS, macOS | NSURLSession. | |
Js | JS | Browser fetch or Node node-fetch. | |
WinHttp | Windows Native | WinHTTP. | |
Curl | Linux/macOS Native | libcurl. |
Pick per platform. Multiplatform projects use expect/actual factories or let Ktor pick via HttpClient() without specifying an engine (not recommended — always be explicit).
Minimum viable client
Clients are expensive — create one per application and reuse. Close on shutdown (or use { ... } for a scoped client).
Configuration block
expectSuccess = true turns non-2xx into ClientRequestException (4xx) or ServerResponseException (5xx); leave false when you need to inspect error bodies.
Making requests
Request builder:
POST with body:
body() deserializes via ContentNegotiation. bodyAsText() returns the raw string.
All HTTP methods
Generic form: client.request(url) { method = HttpMethod.Report }.
Query parameters and URL builder
parameter("k", "v") inside the builder is shorthand for one param.
Headers & auth
Install Auth for persistent credentials with token refresh:
basic { credentials { BasicAuthCredentials(user, pass) } }, digest { ... }, and custom provider { } are the other shapes.
Serialization
ContentNegotiation plus a content-type plugin:
Request-scoped body inference:
Streaming
prepareGet/preparePost keep the response open; use .execute { } to scope channel lifetime.
Multipart / form submission
Retries
retryIf { response -> ... } lets you custom-match.
WebSockets
webSocketSession { } gives you a handle to hold across scopes.
Server-Sent Events
Typesafe requests via Resources
Matches the server-side /ktor-server Resources; sharing the resource class between client and server is the common pattern.
Cookies and caching
HttpCookies honors Set-Cookie; HttpCache respects Cache-Control, ETag, and conditional requests.
Testing with MockEngine
Inspect engine.requestHistory after calls for assertions.
Exception handling
| Exception | When | |
|---|---|---|
ClientRequestException | 4xx response with expectSuccess = true. | |
ServerResponseException | 5xx response with expectSuccess = true. | |
RedirectResponseException | 3xx and redirects disabled. | |
HttpRequestTimeoutException | requestTimeoutMillis exceeded. | |
ConnectTimeoutException | Could not connect within connectTimeoutMillis. | |
SocketTimeoutException | No bytes within socketTimeoutMillis. | |
ResponseException (parent) | Generic catch-all for 3xx/4xx/5xx. |
Anti-patterns
Pitfalls
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingcli/src/main/resources/content/skills/ktor-client/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/clankerguru/opsx/ktor-client)