ktor-patterns

Configure Kotlin HttpClient with ContentNegotiation, HttpTimeout, Auth, and interceptors.

61|17|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/ahmed3elshaer/everything-claude-code-mobile --skill ktor-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ktor-patterns
Source: https://github.com/ahmed3elshaer/everything-claude-code-mobile/tree/main/skills/ktor-patterns
Command: npx skills add https://github.com/ahmed3elshaer/everything-claude-code-mobile --skill ktor-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Android apps require a reliable, scalable HTTP client layer. Ktor provides a coroutine-first client that simplifies networking, serialization, and error handling, reducing boilerplate and helping teams align on a single approach.

Core Features & Use Cases

  • Content negotiation: seamless JSON serialization with kotlinx.serialization or other serializers.
  • Centralized error handling: unified ApiException and safeRequest patterns for robust resilience.
  • Authentication & security: Bearer token support with refresh flow and secure header management.
  • Interceptors & customization: request/response interceptors to inject headers, log traffic, and enforce timeouts.
  • Use Case: Build a small UserApi with endpoints for getUsers, getUser, createUser, updateUser, deleteUser, with mapping from DTOs to domain models.

Quick Start

Use the ktor-patterns skill to configure an HttpClient with OkHttp engine, install ContentNegotiation and HttpTimeout, add Auth, and implement a sample API.

Frequently Asked Questions about ktor-patterns

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

FAQPage Schema
How do I set up HTTP client authentication with Bearer tokens in Android?

Configure Ktor's HttpClient with the Auth plugin to add Bearer token support, including automatic refresh flows. Install the plugin, provide token retrieval logic, and Ktor handles header injection and token lifecycle across requests.

What's the best way to handle errors consistently across Android API calls?

Implement a centralized ApiException pattern with a safeRequest wrapper that catches and maps HTTP errors uniformly. This unified approach reduces boilerplate and ensures consistent error handling across all endpoints in your app.

Can I use Ktor for JSON serialization and deserialization in Android?

Yes. Ktor's ContentNegotiation plugin integrates kotlinx.serialization or other serializers to automatically convert JSON responses to Kotlin data classes and serialize requests, eliminating manual DTO mapping.

How do I add request and response interceptors to log traffic and enforce timeouts?

Install Ktor's HttpTimeout plugin to enforce connection and request limits, then use request/response interceptors to inject custom headers, log traffic, and apply cross-cutting concerns to every request.

Does Ktor work well for building multiple API endpoints in a single Android module?

Yes. Ktor's coroutine-first design and plugin architecture scale efficiently for defining multiple endpoints—getUsers, createUser, updateUser, deleteUser—with shared configuration, authentication, and error handling.

Why use Ktor over other HTTP clients for Android networking?

Ktor reduces boilerplate with built-in serialization, authentication, and interceptors in a single, coroutine-native client. It aligns teams on a unified approach and simplifies resilience patterns compared to lower-level alternatives.