
Ktor Patterns
- 26 installs
- 60 repo stars
- Updated June 14, 2026
- ahmed3elshaer/everything-claude-code-mobile
ktor-patterns is a Claude Code skill that provides Ktor client patterns for Android networking with content negotiation, error handling, and interceptors.
About
ktor-patterns is a Claude Code skill that provides Ktor HTTP client patterns for Android networking. It covers client setup with content negotiation, timeouts, logging, bearer auth with token refresh, API definitions, a safeRequest error-handling wrapper, DTO-to-domain mapping, interceptors, and certificate pinning. A developer uses it when building the network layer of an Android app.
- Ktor client patterns for Android networking
- Content negotiation, timeouts, bearer auth, and interceptors
- Safe request wrapper, DTO mapping, and certificate pinning
Ktor Patterns by the numbers
- 26 all-time installs (skills.sh)
- Ranked #708 of 1,039 Mobile Development skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
ktor-patterns capabilities & compatibility
- Capabilities
- http client setup · error handling · dto mapping · certificate pinning
What ktor-patterns says it does
Modern HTTP client for Kotlin.
Ktor client patterns for Android networking with content negotiation, error handling, and interceptors.
npx skills add https://github.com/ahmed3elshaer/everything-claude-code-mobile --skill ktor-patternsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 26 |
|---|---|
| repo stars | ★ 60 |
| Last updated | June 14, 2026 |
| Repository | ahmed3elshaer/everything-claude-code-mobile ↗ |
What it does
Build an Android network layer with Ktor, including error handling, DTO mapping, interceptors, and certificate pinning.
Who is it for?
Android developers building an HTTP network layer with Ktor.
Skip if: Server-side Ktor or non-Kotlin stacks.
When should I use this skill?
Setting up a Ktor client, error handling, or certificate pinning on Android.
Files
Ktor Client Patterns
Modern HTTP client for Kotlin.
Client Setup
val httpClient = HttpClient(OkHttp) {
// JSON serialization
install(ContentNegotiation) {
json(Json {
ignoreUnknownKeys = true
isLenient = true
prettyPrint = false
})
}
// Timeouts
install(HttpTimeout) {
requestTimeoutMillis = 30_000
connectTimeoutMillis = 10_000
socketTimeoutMillis = 30_000
}
// Logging (debug only)
install(Logging) {
logger = Logger.ANDROID
level = if (BuildConfig.DEBUG) LogLevel.BODY else LogLevel.NONE
}
// Default request config
defaultRequest {
url("https://api.example.com")
contentType(ContentType.Application.Json)
}
// Auth
install(Auth) {
bearer {
loadTokens {
BearerTokens(tokenStorage.accessToken, tokenStorage.refreshToken)
}
refreshTokens {
val response = client.post("auth/refresh") {
setBody(RefreshRequest(tokenStorage.refreshToken))
}
tokenStorage.save(response.body())
BearerTokens(response.body<TokenResponse>().accessToken, response.body<TokenResponse>().refreshToken)
}
}
}
}API Definition
class UserApi(private val client: HttpClient) {
suspend fun getUsers(): List<UserDto> {
return client.get("users").body()
}
suspend fun getUser(id: String): UserDto {
return client.get("users/$id").body()
}
suspend fun createUser(request: CreateUserRequest): UserDto {
return client.post("users") {
setBody(request)
}.body()
}
suspend fun updateUser(id: String, request: UpdateUserRequest): UserDto {
return client.put("users/$id") {
setBody(request)
}.body()
}
suspend fun deleteUser(id: String) {
client.delete("users/$id")
}
}Error Handling
class ApiException(
val statusCode: Int,
override val message: String
) : Exception(message)
suspend inline fun <reified T> HttpClient.safeRequest(
block: HttpRequestBuilder.() -> Unit
): Result<T> = runCatching {
val response = request(block)
if (response.status.isSuccess()) {
response.body<T>()
} else {
throw ApiException(
statusCode = response.status.value,
message = response.bodyAsText()
)
}
}
// Usage
class UserRepository(private val api: UserApi, private val client: HttpClient) {
suspend fun getUser(id: String): Result<User> {
return client.safeRequest<UserDto> {
url("users/$id")
method = HttpMethod.Get
}.map { it.toDomain() }
}
}DTOs and Mapping
@Serializable
data class UserDto(
val id: String,
val email: String,
@SerialName("first_name")
val firstName: String,
@SerialName("created_at")
val createdAt: String
)
fun UserDto.toDomain(): User = User(
id = id,
email = email,
name = firstName,
createdAt = Instant.parse(createdAt)
)Interceptors
val client = HttpClient(OkHttp) {
// Request interceptor
install(HttpSend) {
intercept { request ->
request.headers.append("X-Client-Version", BuildConfig.VERSION_NAME)
execute(request)
}
}
}Certificate Pinning
val client = HttpClient(OkHttp) {
engine {
config {
certificatePinner(
CertificatePinner.Builder()
.add("api.example.com", "sha256/AAAA...")
.add("api.example.com", "sha256/BBBB...") // Backup pin
.build()
)
}
}
}---
Remember: Ktor is coroutine-first. Embrace suspend functions, handle errors properly.
Related skills
FAQ
How does it handle errors?
It defines an ApiException and a safeRequest inline wrapper built on runCatching that throws on non-success status codes.
Does it support certificate pinning?
Yes, it shows OkHttp CertificatePinner setup with primary and backup SHA-256 pins.